Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

iAd memory leaks

schindeschinde Posts: 2New Users
edited January 2011 in iPhone SDK Development
I am trying to implement iAds (onto a view controller) into one of my apps and I am encountering a couple small memory leaks. My ADBannerView displays correctly and hides correctly. However when I test my application on my device with instruments I get a few small memory leaks.

I get about 5 "NSCFString" leaked objects at 16 bytes a piece. The responsible library is Foundation...but knowing that Foundation really does not have any bugs I know it has to do with my code. Also, I know the leaks have to do with iAd, because when I take out all of the iAd code and test...I get no memory leaks.

In my .h file I have:
#import <iAd/iAd.h>
#import <iAd/ADBannerView.h>

@interface HomeViewController : UIViewController <ADBannerViewDelegate>{
	ADBannerView *adView;
	BOOL bannerIsVisible;
}

@property (nonatomic, retain) ADBannerView *adView;
@property (nonatomic, assign) BOOL bannerIsVisible;

@end

In my .m file I have:
@synthesize adView;
@synthesize bannerIsVisible;


- (void)viewDidLoad {
	[super viewDidLoad];
	static NSString * const kADBannerViewClass = @"ADBannerView";
	if (NSClassFromString(kADBannerViewClass) != nil) {
		if (self.adView == nil) {
			self.adView = [[[ADBannerView alloc] init] autorelease];
			self.adView.delegate = self;
			self.adView.frame = CGRectMake(0, -50, 320, 50);
			self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
			[self.view addSubview:self.adView];
		}
	}
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
	if (!self.bannerIsVisible) {
		[UIView beginAnimations:nil context:NULL];
		banner.frame = CGRectOffset(banner.frame, 0, 50);
		[UIView commitAnimations];
		self.bannerIsVisible = YES;
	}	
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
	if (self.bannerIsVisible) {
		[UIView beginAnimations:nil context:NULL];
		banner.frame = CGRectOffset(banner.frame, 0, -50);
		[UIView commitAnimations];
		self.bannerIsVisible = NO;
	}	
}
- (void)dealloc {
	self.adView.delegate = nil;
	self.adView = nil;
        [super dealloc];
}

I do not believe the leaks are because I have it set to autorelease. Maybe the ViewDidLoad is being called multiple times?
When using instruments what usually happens is the application starts running and a few seconds later the ADBannerView is displayed and then I get the "NSCFString" leaks. Also this view controller is the first one displayed when launching the application.


I have been trying multiple things the past couple of days and ultimately I go back to my initial code.

Any help would be appreciated.
Post edited by schinde on

Replies

  • schindeschinde Posts: 2New Users
    edited July 2010
    Has anyone else encountered this? Is it just be a problem with the iAd framework since the leaks are so small?
  • winstwinst Posts: 2New Users
    edited July 2010
    schinde wrote: »
    Has anyone else encountered this? Is it just be a problem with the iAd framework since the leaks are so small?

    I wonder if we are supposed to release the iAd at viewDidUnload?
  • metanurbmetanurb Posts: 2New Users
    edited August 2010
    schinde wrote: »
    Has anyone else encountered this? Is it just be a problem with the iAd framework since the leaks are so small?

    I followed the Apple tutorial on how to implement iAd's to the T.
    I too am having the same issue, have been messing with it for days and going crazy. If I comment out iAd, no leaks.
    I have been releasing on viewDidUnload.
    Have you found out anything more?
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    	if (bannerView)
    	{
            bannerView.delegate = nil;
            [bannerView release];
        }
    }
    

    Cheers.
  • aryaxtaryaxt Posts: 570Registered Users
    edited August 2010
    I get a leak too, it looks like it happenes everytime the adBannerView requests for an ad.
    Any solutions on this?
  • dudeofswimdudeofswim Posts: 139Registered Users
    edited August 2010
    aryaxt wrote: »
    I get a leak too, it looks like it happenes everytime the adBannerView requests for an ad.
    Any solutions on this?

    I'd try the dev forums.

    Quick question. Are you guys creating a new viewcontroller and all manually?

    So I'd like to see the the implementation.

    Basically what else did you do to get iAds up and running. What did you do in interface builder and such

    apparently releasing the iAd in viewDidUnload instead of dealloc seems to fix the problem

    if any of you can help with the iAD's into my project (memory leak or not) I would be willing to pay.
  • Joseph NardoneJoseph Nardone Posts: 639Registered Users @ @ @
    edited August 2010
    aryaxt wrote: »
    I get a leak too, it looks like it happenes everytime the adBannerView requests for an ad.
    Any solutions on this?

    Apple engineer on developer forum said that this is a known issue.

    What are the consequences of these memory leaks?
  • HackHack San FranciscoPosts: 2,079Registered Users @ @ @ @
    edited August 2010
    Apple engineer on developer forum said that this is a known issue.

    What are the consequences of these memory leaks?

    Chance are they are so small you wont see a difference.
  • saba518saba518 Posts: 21Registered Users
    edited August 2010
    Hi u need to release the adView variable twice, since in .h file u retain it and in viewdidload in .m file u used alloc again. so u need to release twice. Don know it works. Let me know the result. All the best.
  • BalillasBalillas Posts: 77Registered Users
    edited August 2010
    Hi

    I'm having the same insue and I'm going crazy.

    What's the way to fix it?

    Thanks
  • BalillasBalillas Posts: 77Registered Users
    edited August 2010
    Hi schinde,

    I want to know if you can solve it. No one?

    Thanks
  • DragonFlyJonesDragonFlyJones Posts: 34Registered Users
    edited November 2010
    schinde wrote: »
    I am trying to implement iAds (onto a view controller) into one of my apps and I am encountering a couple small memory leaks. My ADBannerView displays correctly and hides correctly. However when I test my application on my device with instruments I get a few small memory leaks.

    I get about 5 "NSCFString" leaked objects at 16 bytes a piece. The responsible library is Foundation...but knowing that Foundation really does not have any bugs I know it has to do with my code. Also, I know the leaks have to do with iAd, because when I take out all of the iAd code and test...I get no memory leaks.

    In my .h file I have:
    #import <iAd/iAd.h>
    #import <iAd/ADBannerView.h>
    
    @interface HomeViewController : UIViewController <ADBannerViewDelegate>{
    	ADBannerView *adView;
    	BOOL bannerIsVisible;
    }
    
    @property (nonatomic, retain) ADBannerView *adView;
    @property (nonatomic, assign) BOOL bannerIsVisible;
    
    @end
    

    In my .m file I have:
    @synthesize adView;
    @synthesize bannerIsVisible;
    
    
    - (void)viewDidLoad {
    	[super viewDidLoad];
    	static NSString * const kADBannerViewClass = @"ADBannerView";
    	if (NSClassFromString(kADBannerViewClass) != nil) {
    		if (self.adView == nil) {
    			self.adView = [[[ADBannerView alloc] init] autorelease];
    			self.adView.delegate = self;
    			self.adView.frame = CGRectMake(0, -50, 320, 50);
    			self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    			[self.view addSubview:self.adView];
    		}
    	}
    }
    
    - (void)bannerViewDidLoadAd:(ADBannerView *)banner
    {
    	if (!self.bannerIsVisible) {
    		[UIView beginAnimations:nil context:NULL];
    		banner.frame = CGRectOffset(banner.frame, 0, 50);
    		[UIView commitAnimations];
    		self.bannerIsVisible = YES;
    	}	
    }
    
    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {
    	if (self.bannerIsVisible) {
    		[UIView beginAnimations:nil context:NULL];
    		banner.frame = CGRectOffset(banner.frame, 0, -50);
    		[UIView commitAnimations];
    		self.bannerIsVisible = NO;
    	}	
    }
    - (void)dealloc {
    	self.adView.delegate = nil;
    	self.adView = nil;
            [super dealloc];
    }
    

    I do not believe the leaks are because I have it set to autorelease. Maybe the ViewDidLoad is being called multiple times?
    When using instruments what usually happens is the application starts running and a few seconds later the ADBannerView is displayed and then I get the "NSCFString" leaks. Also this view controller is the first one displayed when launching the application.


    I have been trying multiple things the past couple of days and ultimately I go back to my initial code.

    Any help would be appreciated.

    Looks like you're retaining the iAD in the synthesized property and the retain count is also incremented when you add it to the view. Also, I don't see any explicit release statements. Autoreleasing an object will only call release for you once.
  • jax42jax42 Posts: 3New Users
    edited January 2011
    I'm using interface builder and am wondering how/where do I check to see if my ADBannerView class is instantiated.
Sign In or Register to comment.