filling up kernel_task RAM + SWAP in OS X, Using Declares

After running this lines of code in a loop it somehow eats up all my Mac’s memory.

[code]

s = CGRectMake(0,0,Screen(0).width, Screen(0).height)
p = CGWindowListCreateImage(s, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault)

CGImageRelease§[/code]

I isolated the relevant lines of codes. CGRectMake and CGWindowListCreateImage are soft declares for OS X CoreGraphics.

Can it be, that CGImageRelease is not able to free up Memory when I call the sub CGImageRelease§ ?

Could be anything, e.g. an auto release pool.

What is the general idea to free up memory when using declares?

You’re running this in a loop, so it’s marking the CGImage as release-able, but the OS isn’t going to release it until your loop completes.

I would try this code in a thread, or god forbid you could try app.doevents.

NSAutoReleasePools used to do the job, but these are being phased out by Apple.

doing stuff in a timer may also fix it.