Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimations crash App after going into background
    primarykey
    data
    text
    <p>After looking for some feedback on how to clean up animations once they've finished I implemented the following;</p> <pre><code>- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { UIImageView *AnimationImageEnd = context; [AnimationImageEnd removeFromSuperview]; [AnimationImageEnd release]; } </code></pre> <p>and to set them off (I've removed some of the frames and rotation calcs);</p> <pre><code>UIImageView * AnimationImageStart = [[UIImageView alloc] initWithImage: AnimationImage]; [self addSubview:AnimationImageStart]; [UIView beginAnimations:nil context:AnimationImageStart]; [UIView setAnimationDuration:iSpeed]; AnimationImageStart.transform = transform; [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)]; [UIView setAnimationDelegate:self]; [UIView commitAnimations]; </code></pre> <p>This seems to be working fine and cleaning up all used memory once the animation completes. </p> <p>Since implementing this approach I have now got issues with re-opening the App once it goes into the background if an animation had started before hand. The App is now crashing with the following error;</p> <pre><code>*** -[UIImage _isDecompressing]: message sent to deallocated instance 0x21083ad0 </code></pre> <p>I've had a tinker and it appears to be all down to the release used. If I remove the [AnimationImageEnd release]; the crashes stop (but it obviously starts some memory leaks off..).</p> <p>Is there something simple I am misunderstanding about the Animations and the App entering / re-opening from the background? </p> <p>My guess is that iOS is automatically cleaning up any animations in progress once it enters the background and automatically fires the release to each. If this is the case, should I just simply expect them to have been cleaned up and hold a flag within the applicationDidBecomeActive to bypass the release?</p> <hr> <p><strong>Edit 1</strong> I've read that the finished flag on onAnimationComplete will let me know if the animation completed it's full animation or not. Is it enough to just trust that if it did not finish it has already been cleaned up (removed from superview and released)?</p> <hr> <p><strong>Edit 2</strong></p> <p>As per David's response below I have updated this to a block;</p> <pre><code>[UIView animateWithDuration:5.0f delay:0.0f options:0 animations:^{ imgStart.frame = CGRectMake( 0, 0, 10.0f, 10.0f); } completion:^(BOOL finished){ [imgStart removeFromSuperview]; //This still crashes the App as soon as the App returns from being in the background [imgStart release]; }]; </code></pre> <p>The same behaviour as detailed above is still present. As per Edit 1, is it enough to just assume that whenever the finished BOOL is NO, it has already been cleaned up (removed from superview + released)?</p> <hr> <p>Any information is greatly appreciated.</p> <p>Ralph</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload