dispose object

Software: Away3D 4.x

zeb, Newbie
Posted: 15 February 2014 03:36 PM   Total Posts: 9

Hi,
I try to dispose element from the scene to unerased the memory used

I use the Basic_view.as of away v. 4.1.6

package
{
 import away3d
.containers.*;
 
import away3d.entities.*;
 
import away3d.materials.*;
 
import away3d.primitives.*;
 
import away3d.utils.*;
 
import away3d.debug.AwayStats;
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.Vector3D;

 
 public class 
Main extends Sprite
 {
  
//plane texture
  
[Embed(source="floor_diffuse.jpg")]
  
public static var FloorDiffuse:Class;
  
  
//engine variables
  
private var _view:View3D;
  
  
//scene objects
  
private var _plane:Mesh;
  
  
/**
   * Constructor
   */
  
public function Main()
  
{
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
//setup the view
   
_view = new View3D();
   
addChild(_view);
   
   
// srtup stat
   
var stats AwayStats = new AwayStats(_view);
   
stats.stage.stageWidth stats.width;
   
stats.stage.stageHeight stats.height;
   
addChild(stats);
   
   
//setup the camera
   
_view.camera.= -600;
   
_view.camera.500;
   
_view.camera.lookAt(new Vector3D());
   
   
//setup the scene
   
setupScene();
   
   
//setup the render loop
   
addEventListener(Event.ENTER_FRAME_onEnterFrame);
   
stage.addEventListener(Event.RESIZEonResize);
   
onResize();
   
   
// setup key event
    
stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
  
}
  
/**
   * setup the scene
   */
  
private function setupScene():void
  {
   
   _plane 
= new Mesh(new PlaneGeometry(700700), new TextureMaterial(Cast.bitmapTexture(FloorDiffuse)));
   
_view.scene.addChild(_plane);
   
   
  
}
  
/**
   * remove the scene
   */
  
private function removeScene():void
  {
   
   
for ( var i:int_plane.numChildrenli++)
   
{
    
var el:* = _plane.getChildAt(i)
    
trace(" _"el);
   
   
}
   _plane
.material.dispose();   
   
_plane.geometry.dispose();
   
   
_view.scene.removeChild(_plane);
   
_plane null;
  
}
  
  
/**
  * Key event
  */
  
private function KeyPressed(event:KeyboardEvent)
        
{
   
if ( event.keyCode == 32 )
   
{
    removeScene
();
    
setupScene();
   
}
  }
  
  
/**
   * render loop
   */
  
private function _onEnterFrame(e:Event):void
  {
   _plane
.rotationY += 1;
   
   
_view.render();
  
}
  
  
/**
   * stage listener for resize events
   */
  
private function onResize(event:Event null):void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
  
}
 }


On the beginng the RAM = 70.1M
I press space bar remove and add the same object RAM = 71.5M
If I press space bar again, RAM=72.9M

Please how remove object and clean the memory.
What is the best way.

Thanks for your help.

 

 

   

zeb, Newbie
Posted: 18 February 2014 03:13 PM   Total Posts: 9   [ # 1 ]

Hi,
my fuction to remove object become

private function removeScene():void
  {
   
   
for ( var i:int_plane.numChildrenli++)
   
{
    
var el:* = _plane.getChildAt(i)
    
trace(" _"el);
   
   
}
   
   
var texMat TextureMaterial _plane.material as TextureMaterial;
   
texMat.texture.dispose();
   
texMat.dispose();
   
texMat=null;
   
   
_plane.geometry.dispose();
   
_view.scene.removeChild(_plane);
   
_plane.disposeAsset();
   
_plane.dispose();
   
_plane=null;

But the RAM continues to increase by 0.1.
How to clean object correctly ?

   

zeb, Newbie
Posted: 18 February 2014 03:14 PM   Total Posts: 9   [ # 2 ]

Hi,
my fuction to remove object become

private function removeScene():void
  {
   
   
for ( var i:int_plane.numChildrenli++)
   
{
    
var el:* = _plane.getChildAt(i)
    
trace(" _"el);
   
   
}
   
   
var texMat TextureMaterial _plane.material as TextureMaterial;
   
texMat.texture.dispose();
   
texMat.dispose();
   
texMat=null;
   
   
_plane.geometry.dispose();
   
_view.scene.removeChild(_plane);
   
_plane.disposeAsset();
   
_plane.dispose();
   
_plane=null;

But the RAM continues to increase by 0.1.
How to clean object correctly ?

   
   
‹‹ Mesh not found

X

Away3D Forum

Member Login

Username

Password

Remember_me



X