So in the moment I’m working on something that requires relatively smooth animations, so I figured the best way to do that is to do that with either – a timer, or super-slow drawing steps (meaning instead of moving at least 1 px in a certain amount of time, use no timer but increase pixel location by fractions).
Now in Cocoa (Objective-C to be precise) there are two ways to accomplish this. The one that follows appears to be flawed. So if you do
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
(where 0.1 is 0.1 seconds), it appears to spike memory usage and increase garbage. My application used 23 MB at opening – but when animating using this code, I suddenly used up a whopping 800 MB after 5 seconds of animation.
So my advise is to use this method, which basically has the same effect. However you also need to define a method, define if the timer repeats or not, and the time frame.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(animate) userInfo: nil repeats: YES]; [timer fire];
No idea what userInfo is needed for… just leave it at nil. This method does not increase memory usage at all.
Related posts:

