ios - Proper way to dispose of CAKeyFrameAnimation -
what's proper way dispose of cakeyframeanimation has custom events? made test project demonstrating i'm doing in simplest way possible.
here xcode instruments memory allocations trace
to reproduce did during memory allocations trace, run project. press green button 10 times. (every time press green button, blue square animates).
evaluate memory usage. notice in createanimationeventhandler_position_animationstopped function, i'm disposing of animation. but notice instruments telling me have ton of non-objects leaking memory... what's causing that? , how dispose of cakeyframeanimations correctly?
i tried few different ways dispose of it. here results. after 10 button presses around 30-100kb of non-objects absorbing memory. must doing wrong.
and here's code @ (but it's in project attached):
public override void viewdidload () { base.viewdidload (); // perform additional setup after loading view, typically nib. uiimageview viewtoanimation = new uiimageview(new rectanglef(100, 100, 100, 100)); viewtoanimation.backgroundcolor = uicolor.blue; view.addsubview(viewtoanimation); gobutton = new uibutton(new rectanglef(0, 0, 100, 100)); gobutton.backgroundcolor = uicolor.green; view.addsubview(gobutton); gobutton.touchupinside += delegate { animation = createanimation_position(viewtoanimation, new random().next(0,500), new random().next(0,700), viewtoanimation.center.x, viewtoanimation.center.y, 0.4f, camediatimingfunction.fromname (camediatimingfunction.linear)); viewtoanimation.layer.addanimation(animation, "animation"); }; } public cakeyframeanimation createanimation_position ( uiview view, float tox, float toy, float fromx, float fromy, float duration_s, camediatimingfunction timingfunction ) { appdelegate appdel = (appdelegate)uiapplication.sharedapplication.delegate; cakeyframeanimation positionanimation = cakeyframeanimation.getfromkeypath ("position"); positionanimation.duration = duration_s; positionanimation.timingfunction = timingfunction; pointf tolocation = new pointf(tox, toy); // make path animation cgpath path = new cgpath(); pointf[] lines = {new pointf(fromx, fromy), new pointf(tox, toy)}; path.addlines(lines); positionanimation.path = path; event_started = createanimationeventhandler_position_animationstarted(view, tolocation); positionanimation.animationstarted += event_started; event_stopped = createanimationeventhandler_position_animationstopped(view, positionanimation); positionanimation.animationstopped += event_stopped; return positionanimation; } public eventhandler createanimationeventhandler_position_animationstarted ( uiview view, pointf tolocation ) { eventhandler animationstartedevent = delegate { // apply position change layer view.layer.position = tolocation; }; return animationstartedevent; } public eventhandler<caanimationstateeventargs> createanimationeventhandler_position_animationstopped ( uiview view, cakeyframeanimation animationtodispose ) { eventhandler<caanimationstateeventargs> animationstoppedevent = delegate(object sender, caanimationstateeventargs e) { // console.writeline("finished! finished = " + e.finished); // console.writeline("removing , disposing events"); // animationtodispose.animationstarted -= event_started; // animationtodispose.animationstopped -= event_stopped; // event_started = null; // event_stopped = null; // // // console.writeline("disposing animation"); // animationtodispose.path.dispose(); // reason, calling dispose on animation , not calling dispose on path & events seems more efficient... no idea why animationtodispose.dispose(); }; return animationstoppedevent; }
the great people @ xamarin support gave me resources on memory practices , showed me non-objects not memory leaks. in case, not. turns out i'm disposing correctly.
thanks read , considered helping.
http://docs.xamarin.com/guides/cross-platform/application_fundamentals/memory_perf_best_practices/
Comments
Post a Comment