tags:

views:

202

answers:

4

I must have tried over a dozen incarnations of this code. And looked at +100 answers. IT SHOULD BE so simple. A real basic animation, (using IB this time) but ALWAYS shows a memory leak. NO matter where I put my nil, my release, tried a zillion combinations.

// implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);

     myView.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"1.png"],
                                                         [UIImage imageNamed:@"2.png"],
                                                         [UIImage imageNamed:@"3.png"],
                                                         [UIImage imageNamed:@"4.png"],nil];

    myView.animationDuration = 1.0;

    myView.animationRepeatCount = 0;

    [myView startAnimating];

    [myView release];
     myView = nil;

    [myView.animationImages release];


    NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
}
A: 

Have you tried putting [myView.animationImages release]; before [myView release];? Once you release myView, you can't access myView.animationImages anymore, since there's nothing referencing it.

Chris Long
Yes, tried that. Still same memory leak. That was a desperate attempt! But did not give me an error with [myView release] before [myView.animationImages release], which is kind of strange.
ed potter
A: 

There are all kinds of issues here. You don't own either of the references you're trying to release here. What is the actual leak you're seeing? Simulator or Device?

Start by cleaning up this block of code, getting rid of your releases and your setting to nil.

Joshua Weinberg
Ok, my class created the variables, added the images, etc. Who the heck owns it? How do I find out who "owns" it? My class linked up everything in IB. Now I'm a bit confused. There's only one class here. Bug is in both simulator and device. And removed the release and nils. same bug.
ed potter
A: 

Your question isn't giving enough detail of the whole picture of what is going on with your images array and myView. Without being able to see what's going on in the full picture I would suggest that you try Build -> Clean All Targets and then Build -> Build and Analyze in Xcode. This Build and Analyze is only an option in the Snow Leopard version of Xcode. It will analyze code for potential memory leaks and might help point you in the right direction. It won't pick up on everything, but it does help point out a few things that I tend to miss when I'm in a rush.

Otherwise, I suggest that you post where myView is being allocated and the property declaration of animationImages.

DonnaLea
A: 

I'm not too sure whether i'm right or wrong. but i don't think myView.animationImages needs to be release since it is not init before unless it was init in other parts of your program which i think is highly improbable.

Someone out there who is more knowledgeable in memory management please verify. Thank you!

zerlphr