A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How to detect memory leaks?

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    How to detect memory leaks?

    Just wondered how to detect them and what's the remedy?

    Thanks again!

  2. #2
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    Open task manager or something else that shows you memory usage and if you see the memory going up and up and not coming back down again (usually it'll rise for a bit then fall back down because of the garbage collection) then you've got a memory leak.

    The remedy is to look through your code and find anything that might be continually creating new objects and never deleting them. The onEnterFrame function is a good place to look at first.

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    There's a really nice class package called ActiveGraph, you can download it here:
    http://kirupa.com/forum/showpost.php...3&postcount=14
    That shows you Flash's current memory usage. However, in local test mode, a lot of things that would be garbage-collected in the browser are not properly garbage collected. So there's a little trick that forces garbage collection, for test purposes only, which is to open a LocalConnection. Whether this is a bug or just a convenient hack I don't know, but the following script added to your root code will force consistent garbage collection:

    Code:
    var mt:Timer = new Timer(300);
    mt.addEventListener("timer",mTimeCall);
    mt.start();
    			
    function mTimeCall(evt:TimerEvent) {	
    	try {
    	   new LocalConnection().connect('foo');
    	   new LocalConnection().connect('foo');
    	} catch (e:*) {}
    	stage.setChildIndex(ag,stage.numChildren-1);
    }

  4. #4
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    Quote Originally Posted by joshstrike
    There's a really nice class package called ActiveGraph, you can download it here:
    http://kirupa.com/forum/showpost.php...3&postcount=14
    That shows you Flash's current memory usage. However, in local test mode, a lot of things that would be garbage-collected in the browser are not properly garbage collected. So there's a little trick that forces garbage collection, for test purposes only, which is to open a LocalConnection. Whether this is a bug or just a convenient hack I don't know, but the following script added to your root code will force consistent garbage collection:

    Code:
    var mt:Timer = new Timer(300);
    mt.addEventListener("timer",mTimeCall);
    mt.start();
    			
    function mTimeCall(evt:TimerEvent) {	
    	try {
    	   new LocalConnection().connect('foo');
    	   new LocalConnection().connect('foo');
    	} catch (e:*) {}
    	stage.setChildIndex(ag,stage.numChildren-1);
    }
    That's neat, I'll have to try that out sometime.
    How'd you figure that out, or where'd you find it?

  5. #5
    Junior Member
    Join Date
    Oct 2007
    Posts
    22
    Thanks for that guys!

  6. #6
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    @joshtrike.
    so you can take that piece of code out of your root code, when you put it on the web?

    and this might be a stupid question, but in the activegraph the package's name is net.rezmason.utils. why is this? why not just ActiveGraph? and put it in a folder named ActiveGraph, and then in the flash folder.

  7. #7
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Hey, yeah...you don't want that code in your swf when you go live with a site. I think after a minute or two it seems to crash some wireless routers on the client side. I don't know if that's even possible, but it seems to happen. I do live in countries with spotty internet service, so maybe one thing has nothing to do with another.

    As far as the ActiveGraph package structure, I think you might be looking at a newer version than I have, 'cause mine was just called ActiveGraph. But in any case, just put a folder in the root of your project directory, and make sure the path from there to the ActiveGraph class is reflected in the package name for the class. So if you have myproject/main.swf and myproject/active/ActiveGraph.as then change the package name in the .as file to package active {

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center