Showing posts with label memory. Show all posts
Showing posts with label memory. Show all posts

Monday, May 3, 2010

Mike Ash: Dealing with Retain Cycles

Itt van az egesz.

"Apple's memory management guidelines state that when two objects have a parent-child relationship, the parent should retain the child. If the child needs a reference back to the parent, that reference should be an unretained, weak reference. This allows the parent to be deallocated, which can then release its reference to the child, avoiding a cycle."

Wednesday, January 6, 2010

MPMediaPlayerController problemak

Tovabbra is tobb video egymas utan lejatszasat akarom megoldani es kozben belefutottam 2 problemaba:

1. Ha letrehozok egy MPMoviePlayerController-t akkor annak a retainCount-ja 1 ahogy kell, de amint meghivom rajta a play method-ot a retainCount 3 lesz. (A controller maga modul szinten van deklaralva, de ugyanez tortenik, ha helyben deklaralom, hozom letre es probalom lejatszani.) Igy persze egy sima release sem eleg a MPMoviePlayerDidFinishNotification kezeleseben. (Ugyanakkor, ha a controller-t nil-re allitom majd ujra letrehozom es meghivom a play mehtod-ot akkor mar csak 2 lesz a retainCount es nem 3.) Megneztem az Apple MoviePlayer peldakodjat es ott megjobban elszall a retainCount.

2. A masik problema, hogy ha az MPMoviePayerdidFinishNotification kezeleseben lenullazom a controller-t (akkor is, ha nil-re allitom) es utana egy masik videoval ujra letrehozom, majd meghivom rajta a play method-ot es a notification azert jott, mert a user megnyomta a "next" gombot, akkor a notification ujra megjon amint elindult a masodik video azaz a masodiknak rogton vege lesz. Ha a notification eredetileg azert jott, mert vege volt a videonak, akkor nincs ilyen problema.