This content has been marked as final. Show 4 replies
I believe a variable local to a function would get garbage collected (can't imagine otherwise) but not necessarily when the function returns, garbage collection is done periodically in AS3 to clean up, not every time something is out of scope or deleted.
Your code looks okay, though I'm not sure you need to create a new BitmapData every time the function is called since the BitmapData appears to always be the same. Why not create one outside the function and re-use it within the function? That would save dramatically on processing first of all, and would also help narrow down the memory leak. It may be something in JPEGAsyncEncoder that is the problem, especially since it appears to be a 3rd party library.
What evidence do you have that there's a leak?
Evidence is what is happening in the task manager. Memory increases by 100MB after encoding only 20 images and never gets back to its original state.
The problem has been partially solved by forcing a garbage collection after disposing the bd.
The way I see it, it is definitely an AIR problem
It is not always possible for AIR (or any application) to return all freed memory to the system. Therefore, the fact that memory use doesn't go all the way back down is not indicative of a leak. Rather, a leak is indicated by memory use that grows without bound.
If you force garbage collection but find that memory use is still increasing then the leak is in your application. The garbage collector is entirely reliable at finding freed memory, but if you still have references to objects, it can't reclaim them.