iphone - Animations crash App after going into background -


after looking feedback on how clean animations once they've finished implemented following;

- (void)onanimationcomplete:(nsstring *)animationid finished:(nsnumber *)finished context:(void *)context {     uiimageview *animationimageend = context;     [animationimageend removefromsuperview];     [animationimageend release]; } 

and set them off (i've removed of frames , rotation calcs);

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]; 

this seems working fine , cleaning used memory once animation completes.

since implementing approach have got issues re-opening app once goes background if animation had started before hand. app crashing following error;

*** -[uiimage _isdecompressing]: message sent deallocated instance 0x21083ad0 

i've had tinker , appears down release used. if remove [animationimageend release]; crashes stop (but starts memory leaks off..).

is there simple misunderstanding animations , app entering / re-opening background?

my guess ios automatically cleaning animations in progress once enters background , automatically fires release each. if case, should expect them have been cleaned , hold flag within applicationdidbecomeactive bypass release?


edit 1 i've read finished flag on onanimationcomplete let me know if animation completed it's full animation or not. enough trust if did not finish has been cleaned (removed superview , released)?


edit 2

as per david's response below have updated block;

[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 app app returns being in background                      [imgstart release];                   }]; 

the same behaviour detailed above still present. per edit 1, enough assume whenever finished bool no, has been cleaned (removed superview + released)?


any information appreciated.

ralph

first, please don't use initial capital letter object - reserve classes (it makes reading code harder of us).

generally it's bad practice release objects in callbacks. use dispatch block main queue release object or performselectoronmainthread:, , see if helps.

edit: didn't mean imply needed complete block. reading docs again shows no indication of retain change if animation not complete. since have release in code, not using arc.

non-arc: imgstart alloc/inited, no autorelease, retain count 1. add subview, two. (or system) removes subview, 1. final release makes 0 (i'm ignoring retain/release block itself). cannot see how system release it, not anywhere can seen (its not ivar, viewdidunload cannot release it). right mystery.

suppose converted arc: imgstart released @ start of animation, 2 things retain it, subview array , block. when removed subview array (by whoever), retain count goes down 1, , when block completes release well, causing retain count go 0 released.

if nothing above rings bell or helps, can @ least try , find when/where object getting dealloced. create uiimageview subclass in .m file:

@implementation myiv : uiimageview @end @interface myiv  - (void)dealloc {   [super dealloc];   nslog(@"myiv dealloc!!!!");     } @end 

put breakpoint on log message, , can see getting dealloc'd. i've found helpful in past created arc class class clusters on github, called tracker.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -