Re: [Flashcoders] increasing real memory use

2007-09-13 Thread Muzak
Get rid of the nested functions in loadNewImage()

Assign the enterframe event to a method of the class, using Delegate and make 
sure to keep a reference to the handler so it can be 
removed.
Make the class itself the MovieClipLoader listener, rather than creating a 
seperate listener.

// pseudo code
import mx.utils.Delegate;
class classes.Twee {

private var movieLoader:MovieClipLoader;
private var enterframeDelegate:Function;

function Twee()  {
movieLoader = new MovieClipLoader()
movieLoader.addListener(this);
enterframeDelegate = Delegate.create(this, this.enterframeHandler);
}

function loadNewImage() {
var image_p:MovieClip = root_p.attachMovie("void", "image_mc", 0);
movieLoader.loadClip("2246.jpg", image_p)
}

function onLoadInit(target_mc:MovieClip) {
root_p.onEnterFrame = enterframeDelegate;
   }

function enterframeHandler() {
// do stuff...

//and eventually remove handler
root_p.onEnterFrame = null;
}
}

I'm not very fond (mildly put) of the usage of _root and the movieclip chaining 
going on.
I'd probably go for event dispatching from each class (Een, Twee, Drie) when 
they're done with whatever they're supposed to do, to 
which the Application listens. So the Application takes care of the chain, 
rather than each seperate class.

regards,
Muzak

- Original Message - 
From: "Tom Huynen" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, September 12, 2007 2:21 PM
Subject: [Flashcoders] increasing real memory use


> Hi list,
>
> I created a kioks application that needs to display data (text and images)
> 24/7. The flash projector file however uses more and more real memory from
> the start on.
> I therefore created a simple version of it as can be seen in the code below.
> It contains four classes: Application.as, Een.as, Twee.as and Three.as.
> When this simplified version runs the task manager (windows) or activity
> monitor (mac) reveals a data leak even though I clear up vars and listeners.
> The code is pretty simple, still I can't find out for quite a while now what
> the problem can be.
>
> Regards,
>
> Tom


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] increasing real memory use

2007-09-12 Thread Tom Huynen
Hi list,

I created a kioks application that needs to display data (text and images)
24/7. The flash projector file however uses more and more real memory from
the start on.
I therefore created a simple version of it as can be seen in the code below.
It contains four classes: Application.as, Een.as, Twee.as and Three.as.
When this simplified version runs the task manager (windows) or activity
monitor (mac) reveals a data leak even though I clear up vars and listeners.
The code is pretty simple, still I can't find out for quite a while now what
the problem can be.

Regards,

Tom

// Application.as // Application.as // Application.as // Application.as //
Application.as // Application.as // Application.as // Application.as //
Application.as

import classes.*;

class classes.Application
{
static var root_p:MovieClip = _root;

function Application()
{
var een:Een = new Een();
var twee:Twee = new Twee();
var drie:Drie = new Drie();

root_p.een = een;
root_p.twee = twee;
root_p.drie = drie;

root_p.een.display();
}
}

//Een.as //Een.as //Een.as //Een.as //Een.as //Een.as //Een.as //Een.as
//Een.as //Een.as //Een.as //Een.as //Een.as //Een.as //Een.as //Een.as
//Een.as

import classes.*;

class classes.Een
{
static var root_p:MovieClip = _root;

function Een()
{

}

function display()
{
root_p.twee.display();
}
}

//Twee.as //Twee.as //Twee.as //Twee.as //Twee.as //Twee.as //Twee.as
//Twee.as //Twee.as //Twee.as //Twee.as //Twee.as //Twee.as //Twee.as
//Twee.as

import classes.*;

class classes.Twee
{
static var root_p:MovieClip = _root;

function Twee()
{

}

function display()
{
loadNewImage();
}

function loadNewImage()
{
var _this:Object = this;

var image_p:MovieClip = root_p.attachMovie("void", "image_mc", 0);

var ml:MovieClipLoader = new MovieClipLoader();
var l:Object = new Object();

l.onLoadInit = function(target_mc:MovieClip)
{
if(target_mc == image_p)
{
var c:Number = 0;

root_p.onEnterFrame = function()
{
if(c == 20)
{
c = null
this.onEnterFrame = null;
delete this.onEnterFrame;
root_p.drie.display(ml, l);
}
else
{
c++
}
}
}
}

ml.addListener(l);

ml.loadClip("2246.jpg", image_p);
}
}

//Drie.as //Drie.as //Drie.as //Drie.as //Drie.as //Drie.as //Drie.as
//Drie.as //Drie.as //Drie.as //Drie.as //Drie.as //Drie.as //Drie.as
//Drie.as //Drie.as //Drie.as //


import classes.*;

class classes.Drie
{
static var root_p:MovieClip = _root;

function Drie()
{

}

function display(ml:MovieClipLoader, l:Object)
{

ml.unloadClip(root_p.image_mc);
root_p.image_mc.removeMovieClip();

ml.removeListener(l);

ml = null;
l = null;

var c:Number = 0;

root_p.onEnterFrame = function()
{
if(c == 400)
{
this.onEnterFrame = null;
delete this.onEnterFrame;
c = null;
root_p.een.display();
}
else
{
c++
}
}
}
}
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com