views:

60

answers:

1

Hi All,

I have created a UI that displays 3-4 charts in the UI.

I notice the following

  1. As soon as these charts load up the IE memory shoots up to around 400 Mb which is understandable because some of these charts are like tables displaying upto a thousand rows.

  2. I notice the more I refresh these charts the more IE memory increases.

From a simple walkthrough of the code multiple times, I couldn't find any leaks or any data structures who size was increasing. I am using Flex builder 2. I have a few questions:

  1. When does Flash free the memory ? Can I IE return that memory to the OS ?
  2. Is there a known memory leak in
    Flash ?
  3. What are the tools that could possible help me ?
  4. Does any programming best practise like making unused Objects explicitly as null, help ?

thank you very much.

I have one more question, it seems that the IE doesn't release any memory at all unless it is minimised ?

+1  A: 

1) This article will explain everything about Garbage Collection (which is how managed languages take care of memory management). Basically you have no control of when it runs(there is a hack to force it but you shouldn't be using it)

http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html

and this

http://blog.flexmonkeypatches.com/2007/03/28/flash-player-memory-management-and-garbage-collection-redux-2/

2) There shouldn't be a leak as long as you are ensuring that objects no longer needed are able to be garbage collected. That being said I am not familiar with Flex and perhaps there is a bug in the framework??? EDIT: There seems to be a lot of people who have problems with flex+ie and memory leaks.

3) System.totalMemory will at least help you see how much memory you are using. EDIT:Forgot to mention if you upgrade to Flex Builder 3 it comes with memory profiler tools

4) Yes, if you no longer need something setting it to null is good practise. Don't forget to remove any event listeners and make use of weak listeners where you can. If there is still a reference to something then it won't be marked for the garbage collector.

Allan
I have one more question, it seems that the IE doesn't release any memory at all unless it is minimised ?
Geek
hmm actually google seems to reveal a lot of results regarding flex+ie+charts memory leak. http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html <-- a lot of comments. Maybe have a read through them :S
Allan
Allan, I am still googling for the correct answer :-). One point I want to add is "may be there is no leak at all". The moment I minimise the IE Window the 200MB allocated comes down to say 5Mb, what I am not noticing is that as long as the IE window is open I don't see a decrease in memory used but the moment you minimise it the memory is released. Have you seen this ?
Geek
I now understand that minimising the window trims the working set but does that invoke GC of Flash ? Is there a way to have an upper bound on the memory used by flash.
Geek
I am not sure of the internals and I am pretty sure you can not se an upper bound. However maybe you can check the total memory being used. If its greater than a certain threshold force the garbage collector. http://www.gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html shows snippet for checking the total memory. Where he calls abort perhaps you could force the garbage collector (further down shows the code for that).
Allan