I am having an iphone app with admob on two screens’s viewdidLoad
My code is:
AbMob =[[GADBannerView alloc]initWithFrame:CGRectMake(0.0,self.view.frame.size.height-195, 320, 50)];
AbMob.adUnitID = AdMob_ID;
AbMob.rootViewController = self;
[self.view addSubview:AbMob];
GADRequest *r = [[GADRequest alloc] init];
r.testing = NO;
[AbMob loadRequest:r];
Problem is this code works fine on one screen but crashes on other screen with error
* -[GADOpener didOpen]: message sent to deallocated instance
0x6074750
Can anybody tell me what could be the problem
You have a retain/release problem somewhere in your code. You say it works in one view, but not another – this makes me believe that you are storing this instance outside of your view controllers. The
message sent to deallocated instanceissue is due to you trying to use a variable that has been removed from memory somewhere in the code before this error pops up. You need to ensure that the view controller that is creating this object is properlyretaining it so that it does not get deallocated before you need to use it again with:It sounds like you may need to brush up on your memory management documentation, but the gist of it is that anywhere you are calling
alloc, you are managing that memory and need to callreleasewhen you are done with it. If you need a variable to stick around for longer than anautoreleased object is living for, then you need to create an instance variable andretainthe object yourself with ivar properties@property (nonatomic, retain).