ios iad和admob整合导致内存泄漏?

时间:2012-02-16 19:55:09

标签: iphone ios memory-leaks admob iad

我使用此代码,如果iad无法加载,则查找admob。一切似乎工作得很好,除了仪器我注意到一个大的内存峰值随时调用一个admob。经过多次仪器后,我只得到一次内存泄漏,当调用一个admob时我很确定。我看到有些人用admob谈论内存泄漏,但我不确定这是否已修复。

我的代码看起来不错吗?如果是这样希望这可以帮助某人,但我最终可能会从我的应用程序中取出admob,因为它似乎会在一段时间后大大减慢程序的速度。我也没有意识到sdk接近8mb。

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible) {
        [bannerView_ removeFromSuperview];
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0.0, -50.0);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;

    }
}

-(void)callAdMob {
    // Create a view of the standard size at the bottom of the screen.
    bannerView_ = [[GADBannerView alloc]
                   initWithFrame:CGRectMake(0.0,
                                            self.view.frame.size.height -
                                            GAD_SIZE_320x50.height,
                                            GAD_SIZE_320x50.width,
                                            GAD_SIZE_320x50.height)];

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = @"";

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];


}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible) {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0.0, 50.0);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
        NSLog(@"bannerview did not receive any banner due to %@", error);
        [self callAdMob];

    }
}
- (void)viewDidLoad
{

        [super viewDidLoad];
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectOffset(adView.frame, 0.0, 367.0);
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    [self.view addSubview:adView];
    adView.delegate = self;
    self.bannerIsVisible = NO;
}

1 个答案:

答案 0 :(得分:0)

在Profiler中运行时,泄漏是否列为GeneralBlock-1024和GeneralBlock-56?如果是这种情况,听起来就像iOS中的UIWebView泄漏一段时间。它似乎与通过HTTP发出HTTP请求或XML请求有关。

Apple应该已经在iOS 5中解决了这个问题,但它仍然存在于以前版本的iOS中。