Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Mediators / Notification and System Memory AS3 Flash  (Read 9802 times)
Dal
Jr. Member
**
Posts: 16


View Profile Email
« on: March 03, 2009, 02:17:36 »

Sup Pure MVC'ers,
So basically I need some help, as we all do ;) and I suspect there is more of a question for Cliff than anyone.

What I have is a base mediator( responsible for any tweening, adding and removing itself from the stage ).
BaseMediator is extended by SpriteMediator( sprite mediator is responsible for for any graphics, solid fills, les's, boxes, lines..... ) then I have ImageMediator( you guessed it, responsible for for loading and masking images.... ).

Any new modules I need to make extend mediators - ImageMediator / SoundMediator / MovieMediator, whatever. So all I have to do is call my new module Mediator and the notification trickles down using a switch case command with super.handleNotification( note ) in the default, which I thought was pretty cool - however when I checked the system memory each time a note is passed to its parent the system memory increases by 4k. Which I know is not much, but through 4 different mediators and then to a command to load an image is 20k, plus the system has listener events called on resize, keyboard..... all mounting up.

Basic debocal, when I load a background image the memory usage was going up 2-3megs when the image is 200k. So after this long winded - whats going on, my question is this does the mvc system garbage collect the notification objects that is sent to mediators and commands and if not, how would you suggest implimenting this feature???


Cheers
~D
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 04, 2009, 05:27:25 »

Yes, garbage is collected according to the normal rules of the Flash Player.
As with any AS3 program you have to make sure you don't hang on to any references you don't  need. Its hard to tell what's going on without driving your debugger myself, but I can tell you that mediators shouldn't be added to the stage, so at least one thing is not quite right about your implementation.

Meditate on your app design a bit and repost with a little more detail about where you think the problem may lie. I can't concieve what could cause a 2-3 meg jump when a 200k image is loaded, its certainly not overhead you can expect PureMVC to add. The entire library is only 12k. You'd have to be making a bargeload of  class instances to make this happen.   
If you're using Flex/Flex Builder, try profiling the app.

-=Cliff>
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #2 on: March 04, 2009, 07:02:16 »

Are you making bitmap copies anywhere along the way and storing that information? It definitely sounds like you are caching references somewhere, through events maybe?
Logged
Dal
Jr. Member
**
Posts: 16


View Profile Email
« Reply #3 on: March 04, 2009, 03:50:48 »

Hi Cliff / Jason,
Thanks for your help guys

Sorry Cliff I should have explained a little better the mediator's are not added to the stage, they create the necessary components - custom, sprite or otherwise and control everything about them.
I have been reading a lot on Garbage Collection as well, seems daft that you can't control it.
Basically my app is a full flash site, so between each page there are new sprites, listeners and any custom components....
Lets say you jump between four different galleries - 20 images on each gallery.
So thats around 80 images, each with  their own lens sprite, box sprite, bkg solid sprite.
Each one of these images is associated to a large that can or cannot be loaded into the background, depends on the user.
Each gallery has an alpha, and a line to define it.
So Sprite wise you are looking at say 240 sitting in memory between those pages - is that a bargeload????
I didn't really want to clear these as it is nice to just take them off the display list and them throw them back when the user goes to that page - lazy way of having the system remember where the user last was on that page.
Is there any profile thing for straight flash?

Hi Jason, yes I am storing the bitmap data of any image loaded in a proxy so they are only ever loaded once..... This bad??
All my events are deleted between pages.
When I want to remove an object completely I use 'object = null' - which I do for the large images.

But I believe the problem is somewhere around the UILoader or the caching.....
In the image load command I have traced the System.totalMemory when I start the UILoader and then when it hits the complete handler, on the complete I get the massive jump....
Would something in there be doing it??

mmmmmm
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #4 on: March 04, 2009, 09:25:02 »

Remember to clear your UILoader after each load or it'll save a reference as well.

And you can profile Flash apps using the profiler in FlexBuilder. Just publish your swf with debug allowed (in the publish settings). Then in Flex go to Profile Perspective -> profile ->  Profile External and select the Flash file to load. Voila, Flex profiling of a Flash app!
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #5 on: March 04, 2009, 09:43:13 »

Bitmap data is kind of a bear to get rid of on occasions. I have found myself digging into the bitmapdata and running dispose then null:

bitmap.bitmapData.dispose();
bitmap.bitmapData = null

that does the trick every time ;)
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Dal
Jr. Member
**
Posts: 16


View Profile Email
« Reply #6 on: March 05, 2009, 03:20:20 »

thankyou guys, i'll give it a whirl and post back my rersults  :)
Logged
Pages: [1]
Print