Memory Leak when Google Analytics sends a hit

一笑奈何 提交于 2019-12-08 21:08:32

I had the same issue.

In my case that was because I use Core Data and NSManagedObjectContextDidSaveNotification to merge updates from a background process, resulting in a exception as described in this post :

The solution I used was to add the managedObjectContext itself as object of the NSNotificaition declaration :

ObjC

[[NSNotificationCenter defaultCenter] addObserver:self 
                                  selector:@selector(managedObjectContextDidSave:) 
                                  name:NSManagedObjectContextDidSaveNotification 
                                  object:self.managedObjectContext];

Swift

NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextDidSaveNotification,
            object: self.managedObjectContext,
            queue: nil)

Did the trick for me, no more memory leak.

Hope it could help.

Once the events are fired, it will take a couple of minutes to get reflected in dashboard. IT is expected that the user should have little patience. This is one way of looking at it.

With respect to code, It is better to dispatch the events manually. IT will certainly get reflected in dashboard.

id newTracker = [[GAI sharedInstance]trackerWithTrackingId:googlePropertyId];
[GAI sharedInstance].defaultTracker = newTracker; // Set newTracker as the default tracker globally.
[GAI sharedInstance].debug = YES;
DebugLog(@"Events log : %@",objAnalytics.event_description);
[newTracker trackEventWithCategory:objAnalytics.event_name
                            withAction:objAnalytics.event_description
                             withLabel:objAnalytics.event_name
                             withValue:[NSNumber numberWithInt:100]];

Please try dispatching the events manually. This will work for sure (at least it worked for me this way).

[[GAI sharedInstance]dispatch];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!