问题
I'm trying to use Google Analytics SDK v3.10 for iOS.
I added all dependencies and headers, then in my app delegate, method :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
, I added those lines :
[[GAI sharedInstance] setDispatchInterval:20.0];
[[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXXXXXX-X"];
[[GAI sharedInstance].logger setLogLevel:kGAILogLevelVerbose];
with the proper tracking id.
In my landing view, method viewDidAppear, I added the lines
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"MyLandingView"];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
It leads to an horrible memory leak (about +1mb/s) and a freeze with those logs :
Apr 20 08:07:47 iPad-of-Pitt MyAppName[920] <Warning>: void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
Is this a known bug ? Any clue on how to avoid that ?
Thanks in advance !
EDIT : duplicated this question in google groups https://groups.google.com/forum/?fromgroups#!topic/ga-mobile-app-analytics/0goRZOc3vk0
EDIT 2 : also posted the issue here https://code.google.com/p/analytics-issues/issues/detail?id=617&thanks=617&ts=1429543879
回答1:
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.
回答2:
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];
来源:https://stackoverflow.com/questions/29746209/memory-leak-when-google-analytics-sends-a-hit