2016-03-19 5 views
1

AdMobとスプライトキットに問題があります。AdMobのインタースティシャルメモリリーク?スプライトキット

毎回広告が表示されたり読み込まれたりすると、メモリ使用量が大幅に増加します。 EndGameSceneを開くと、 "showAd"が呼び出され、再生ボタンが押されると "loadAd"が表示されます。

広告はうまくいきます。

ゲームが開始されると、メモリ使用量は50MBのようなものになり、後で少なくとも70-100MBになります!

だから私が間違って何をすべきか:

GameViewController.m

- (void)viewDidLoad{ 
[super viewDidLoad]; 



[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"loadAd" object:nil]; 

self.interstitial = [self createAndLoadInterstitial]; 
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-<id>"]; 

GADRequest *request = [GADRequest request]; 
// Requests test ads on test devices. 
request.testDevices = @[@"0000000"]; 
[self.interstitial loadRequest:request]; 

//etc 
} 


- (void)handleNotification:(NSNotification *)notification{ 
if ([notification.name isEqualToString:@"showAd"]) { 
    if (self.interstitial.isReady) { 
     [ self.interstitial presentFromRootViewController:self]; 
    } 

    else { 

    } 

} 

if ([notification.name isEqualToString:@"loadAd"]) { 
    self.interstitial = [self createAndLoadInterstitial]; 
} 
} 
- (GADInterstitial *)createAndLoadInterstitial { 
GADInterstitial *interstitial = 
[[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-<id>"]; 
interstitial.delegate = self; 
[interstitial loadRequest:[GADRequest request]]; 
return interstitial;} 

ありがとう!

答えて

1

ロードリクエストを開始する新しいGADInterstitialオブジェクトを毎回作成しています。私は答えを待っているので、再びメモリから解放されることはないと思います。 より良い方法は、GADInterstitialをグローバルプロパティに格納し、新しい広告が必要な場合は新しいloadRequestを呼び出すことです。

関連する問題