iAD内存泄漏

时间:2012-04-26 00:11:26

标签: iphone objective-c memory-leaks iad

此代码泄漏:

   self.adView = ADBannerView* tempAddBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.adView.frame = CGRectOffset(adView.frame, 0, 416);
self.adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
self.adView.delegate = self;
self.bannerIsVisible = NO;

显然是因为adView从未发布过。释放它的最佳位置在哪里?

我修复它的尝试崩溃了:

  ADBannerView* tempAddBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    tempAddBannerView.frame = CGRectOffset(adView.frame, 0, 416);
    tempAddBannerView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
    tempAddBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;


self.adView = tempAddBannerView;
[tempAddBannerView release];
[self.view addSubview:adView];
self.adView.delegate = self;
self.bannerIsVisible = NO;

1 个答案:

答案 0 :(得分:1)

代码[self.view addSubview:adView];会保留UIView,因此您应该安全地在该行之后释放它。