Skip to main content
March 28, 2013
Answered

How to make external SWFs garbage collected in Air for iOS?

  • March 28, 2013
  • 1 reply
  • 1304 views

My app uses lots of external SWFs( well they are actually included in the app with a folder but they aren't embeded ) and they do not contain any bitmapdata, only vector graphics. The problem I'm having is that they seem to be never garbage collected and System.privateMemory keeps increasing as the app loads more SWFs.

Since those SWFs only contain vector graphics, I simply nullify all the variables that are holding reference to SWF file and call System.gc().. But it doesn't seem to be working. What would I need to do for the garbage collector to clean the SWFs?

I'm using Air for iOS 3.5.0.1060 and ActionScript3.0.


This topic has been closed for replies.
Correct answer Nabren

Ya - I have found they are not always garbage collected when you expect them to be. It's not that they are "missed" just that AIR decides to wait before garbage collecting. I have found as the app continues to run they will eventually be garbage collected at very unpredictable times as long as you truly have no remaining references to them.

1 reply

Nabren
Inspiring
March 28, 2013

Sometimes you might have to call System.gc() twice in a row for some things to be garbage collected. Also note that doesn't guarantee anything. Try running your memory way up and then leave it running idle for like 15-20 minutes and see if they get cleaned up.

March 29, 2013

Yes I'm calling System.gc() twice. I tried using loader.unloadAndStop(true) and it seems SWFs are being garbage collected but another problem has surfaced. When repeatedly loading and unloading SWF in a short period, the air garbage collector sometimes fails to work.

I've tested loading and unloading same SWF 50k times and checked trace.  Occasionally, garbage collector misses to collect garbage like below( swf #45119 is not being garbage collected).

[UnloadSWF] main.swf/[[DYNAMIC]]/45115

[UnloadSWF] main.swf/[[DYNAMIC]]/45116

[UnloadSWF] main.swf/[[DYNAMIC]]/45117

[UnloadSWF] main.swf/[[DYNAMIC]]/45118

[UnloadSWF] main.swf/[[DYNAMIC]]/45120

[UnloadSWF] main.swf/[[DYNAMIC]]/45121

.

Nabren
NabrenCorrect answer
Inspiring
March 29, 2013

Ya - I have found they are not always garbage collected when you expect them to be. It's not that they are "missed" just that AIR decides to wait before garbage collecting. I have found as the app continues to run they will eventually be garbage collected at very unpredictable times as long as you truly have no remaining references to them.