views:

35

answers:

1

I have a flipView class that I allocate and initiate. But, when I release it the app crashes. If I don't release it, the app works fine, so it seems. The error message I receive when I release it is:

Malloc - error for object: object pointer being freed was not allocated.

If you could please assist me, I would be grateful.

- (IBAction)showInfo {
    FlippedProduceView *flippedView = [[FlippedProduceView alloc]initWithIndexPath:index];

    flippedView.flipDelegate = self;

    flippedView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentModalViewController:flippedView animated:YES];

    //[flippedView release]; //******** Maybe A Memory Leak *********\\
}
A: 

Your presentModalViewController: message should call retain on the flippedView. That will keep it from being deallocated until presentModalViewController:'s purpose for it is complete. You can then call [flippedView release] as you should at the end of this routine. Unless there is something else missing?

fbrereto
Thank you fbrereto for answering my question. I am a complete newbie and working on my first app. I am almost finished but this problem is holding me back. I don't understand how I would code the expression you mentioned. Would it be like this ?: FlippedProduceView *fView = [[FlippedProduceView alloc]initWithIndexPath:index]; [fView retain]; fView.flipDelegate = self; fView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:fView animated:YES]; NSLog(@"Retain Count fView:%d",[fView retainCount]); [fView release];
Ms. Ryann
okay, would it look like this? [self presentModalViewController:[fView retain] animated:YES];
Ms. Ryann
Inside of `presentModalViewController` you would call `retain` on the view you receive. You would not need to call `retain` in `showInfo` as the alloc/init phase does that automatically for you. You can then call `release` from within `showInfo` and the object will still exist because it was retained by `presentModalViewController`.
fbrereto