ios - ADInterstitialAd causing memory issues -
i've been developing iphone / ipad game using sprite kit , in between each round load interstitial advert.
the interstitial loaded on main gameviewcontroller
, sits on top of skview
. use series of observers trigger , cancel adverts , seems work fine.
however, i've noticed serious memory issues , after 4 or 5 rounds app crash. appears directly related iad interstitial. i've attached code , can see i'm deallocating objects, memory foot print not seem drop. using arc too.
does know causing issue? did read here: iad & admob heavy on memory webkit
view seems hold on contents. need find way fix this, code gameviewcontroller
follows:
#pragma mark - game load -(void)loadstartscreen{ _theview = (skview *) self.view; _theview.showsfps = yes; _theview.showsnodecount = yes; //sprite kit applies additional optimizations improve rendering performance _theview.ignoressiblingorder = yes; // create , configure scene. _thescene = [mainmenuscene scenewithsize:_theview.bounds.size]; _thescene.scalemode = skscenescalemodeaspectfill; _thescene.backgroundcolor = [uicolor graycolor]; // present scene [_theview presentscene:_thescene]; // setup observer [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(requestfullscreenad) name:@"requestadvert" object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(showfullscreenad) name:@"showadvert" object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(canceladverts) name:@"canceladvert" object:nil]; } #pragma mark - advert creation , support -(void)requestfullscreenad { // run process on main thread in background queue dispatch_async(bgqueue, ^{ if (_requestingad == no) { _interstitial = [[adinterstitialad alloc]init]; _interstitial.delegate = self; self.interstitialpresentationpolicy = adinterstitialpresentationpolicymanual; nslog(@"ad request"); _requestingad = yes; } }); } -(void)showfullscreenad{ if (_adloaded) { cgrect interstitialframe = self.view.bounds; interstitialframe.origin = cgpointmake(0, 0); _adview = [[uiview alloc] initwithframe:interstitialframe]; [self.view addsubview:_adview]; [_interstitial presentinview:_adview]; _button = [uibutton buttonwithtype:uibuttontypecustom]; [_button addtarget:self action:@selector(closead:) forcontrolevents:uicontroleventtouchdown]; _button.backgroundcolor = [uicolor clearcolor]; [_button setbackgroundimage:[uiimage imagenamed:kclosead] forstate:uicontrolstatenormal]; _button.frame = cgrectmake(10, 10, 40, 40); _button.alpha = 0.75; [_adview insertsubview:_button abovesubview:_adview]; [uiview beginanimations:@"animateadbanneron" context:nil]; [uiview setanimationduration:1]; [_adview setalpha:1]; [uiview commitanimations]; } } -(void)closead:(id)sender { [uiview beginanimations:@"animateadbanneroff" context:nil]; [uiview setanimationduration:1]; [_adview setalpha:0]; [uiview commitanimations]; _adview=nil; _requestingad = no; _button = nil; _interstitial.delegate = nil; _interstitial = nil; // notification ad complete [[nsnotificationcenter defaultcenter] postnotificationname:@"adclosed" object:nil]; } -(void)canceladverts{ [_interstitial cancelaction]; _adview=nil; _requestingad = no; _button = nil; _interstitial.delegate = nil; _interstitial = nil; } #pragma mark - iad delegate -(void)interstitialad:(adinterstitialad *)interstitialad didfailwitherror:(nserror *)error { [_interstitial cancelaction]; _adview=nil; _requestingad = no; _button = nil; _interstitial.delegate = nil; _interstitial = nil; nslog(@"ad didfailwitherror"); nslog(@"%@", error); // request advert if failed //[self requestfullscreenad]; } -(void)interstitialaddidload:(adinterstitialad *)interstitialad { if (interstitialad.loaded) { _adloaded = yes; [[nsnotificationcenter defaultcenter]postnotificationname:@"adloaded" object:nil]; } nslog(@"ad didload"); } -(void)interstitialaddidunload:(adinterstitialad *)interstitialad { [self closead:nil]; nslog(@"ad didunload"); } -(void)interstitialadactiondidfinish:(adinterstitialad *)interstitialad { [self closead:nil]; nslog(@"ad didfinish"); }
then in level complete skscene:
#pragma mark - scene appears -(void)didmovetoview:(skview *)view { // request advert if advert removal not purchased if (![[[userdetails sharedmanager]iapadsremoved]boolvalue]) { // send request ad notification [[nsnotificationcenter defaultcenter]postnotificationname:@"requestadvert" object:nil]; // add loaded notification [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(adloaded) name:@"adloaded" object:nil]; // add completed [[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(adshowcompleted) name:@"adclosed" object:nil]; } // setup ui [self createui]; if (![[unlockcontroller sharedmanager]allunlocksopen]) { // check unlocks [[unlockcontroller sharedmanager]checkunlocks:[[userdetails sharedmanager]usertotalscore]+[[userdetails sharedmanager]userlevelscore]]; // next unlock [self getnextunlockscore]; // set bar correct increment [unlockbar setbarvalues:[[userdetails sharedmanager]usertotalscore]+[[userdetails sharedmanager]userlevelscore] increment:[[userdetails sharedmanager]usertotalscore] nextobject:nextscore]; } else{ [self allunlocksopen]; } // pre add button preadbuttonpress = 3; // variables startcount = 0; unlockitemscount = 0; allunlocks = [[unlockcontroller sharedmanager]finalunlockopen]; // start unlocks sequence [self performselector:@selector(runrewards) withobject:nil afterdelay:1.0]; } -(void)willmovefromview:(skview *)view{ // cancel adverts [[nsnotificationcenter defaultcenter]postnotificationname:@"canceladvert" object:nil]; // remove observers [[nsnotificationcenter defaultcenter]removeobserver:@"adclosed"]; [[nsnotificationcenter defaultcenter]removeobserver:@"adloaded"]; }
was memory issue core code rather iad causing memory leaks.
Comments
Post a Comment