简体   繁体   English

ios iad和admob集成导致内存泄漏?

[英]ios iad and admob intergration causing memory leak?

I use this code where if an iad fails to load it looks for an admob. 我使用此代码,如果iad无法加载,它将查找admob。 Everything appears to work fine except in instruments I have noticed a large memory spike anytime an admob gets called. 一切似乎都工作正常,但在乐器中,我发现只要调用admob就会出现大量内存高峰。 After putting this through instruments multiple times I only got a memory leak once which im pretty sure occurred when an admob was called. 在多次通过仪器处理之后,我只遇到一次内存泄漏,这很确定是在调用admob时发生的。 I have seen some people talk about memory leaks with admob but i wasn't sure if this was fixed or not. 我见过有人用admob谈论内存泄漏,但是我不确定这是否已解决。

Does my code look good? 我的代码看起来不错吗? If so hopefully this helps someone out but I may end up taking admob out of my app cause it seems to drastically slow down the program after awhile. 如果可以的话,这可以帮助某人,但是我可能最终会从我的应用程序中删除admob,因为一段时间后它似乎会大大降低该程序的速度。 Also I did not realize the sdk is close to 8mb. 我也没有意识到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;
}

When you run it in the profiler, is the leak listed as GeneralBlock-1024 and GeneralBlock-56? 在事件探查器中运行泄漏时,泄漏是否列为GeneralBlock-1024和GeneralBlock-56? If this is the case, sounds like a UIWebView leak that's been in iOS a while. 如果是这种情况,听起来像是iOS上出现过一段时间的UIWebView泄漏。 It seems to be tied to making HTTP requests, or XML requests over HTTP. 它似乎与通过HTTP发出HTTP请求或XML请求有关。

Apple should have fixed this in iOS 5 but it still exists in previous versions of iOS. Apple应该已经在iOS 5中修复了此问题,但在以前的iOS版本中仍然存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM