Advertise here




Advertise here

Howdy, Stranger!

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

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

iAd memory leaks

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
    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
    schinde;228336 said:
    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
    schinde;228336 said:
    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
    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
    aryaxt;230753 said:
    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: 585Registered Users
    aryaxt;230753 said:
    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?
  • Bertrand21Bertrand21 Posts: 2,009Registered Users
    Joseph Nardone;230799 said:
    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.
    Acquired.
  • saba518saba518 Posts: 21Registered Users
    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
    Hi

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

    What's the way to fix it?

    Thanks
  • BalillasBalillas Posts: 77Registered Users
    Hi schinde,

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

    Thanks
  • DragonFlyJonesDragonFlyJones Posts: 34Registered Users
    schinde;228031 said:
    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
    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.