How to properly destroy a class.

I'm trying to make multiple dynamically created MovieClip classes move across the stage and have created an ENTER_FRAME Event Listener in each one.
Usually, when I remove a MovieClip, I simply remove them from the container and splice their pointer from the array.
But it appears that doing this does not remove Event Listeners or even the functions I've writted inside the class and thus each "removed" MovieClip produces errors every frame. (Even without the errors, I would still not want those things running in the background)
So my question is rather simple, what is the best way of disposing of a MovieClip class (or classes in general) and making sure that no residues are left behind?
Thanks in advance.

it should.  but gc just doesn't work very well so i can't tell if it's any benefit to use weak references (even when you remove them).
try the code below the dotted line.  actually, comment out the line that nulls the movieclips so you can see that it only takes 10 or so iterations of f() to exceed 100kb of memory.  then uncomment the nulling line and retest.  you should see many more iterations, somewhere around 45.  so gc is occuring but you shouldn't see memory reach 100kb.  memory should reach some level and then hover around that level.
that's the best that gc does.  it's better than doing nothing but it doesn't work well.
i wouldn't expect any improvement on that by adding a weak listener but i see a benefit.  i just am not sure it's signifcant (and i'm not sure it's consistant) over no listener.
same adding a strong listener.
and you can add a weak and remove it.
and you can add a strong and remove it
at the end of all that all i can conclude is, gc doesn't work well.  the best gc i saw was adding a strong listener and NOT removing it.
i don't know if that's specific to my system.  and i don't know if that's specific to my system at the time i tested.  maybe with other background activity i would get a different result.
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
var tl:MovieClip = this;
var startNum:int = 0;
var n:int=10000;
var t:Timer = new Timer(30,0);
t.addEventListener(TimerEvent.TIMER,f);
t.start();
f();
function f(e:TimerEvent=null):void {
    for (var i:int=startNum; i<n+startNum; i++) {
        tl["mc"+i] = new MovieClip();
        //tl["mc"+i].addEventListener(MouseEvent.CLICK, cl,false,0,true);
        //tl["mc"+i].addEventListener(MouseEvent.CLICK, cl);
        //tl["mc"+i].removeEventListener(MouseEvent.CLICK, cl);
        tl["mc"+i] = null
    startNum = i;
    var mem:Number = Math.round(System.totalMemory/1024);
    trace(startNum/n,mem)
    if(mem>100000){
        t.stop();
function cl(e:Event):void{

Similar Messages

  • How to Properly Destroy Quicktime ActiveX Object?

    Hi,
    Does anyone have experience with Quicktime ActiveX objects?  I'm having an issue about destroying/unloading the objects.  When my compiled executable is closed (either programtically through 'Quit Labview' or by selecting 'File-->Exit'), Windows 7 detects a crash and displays:
    So I'm guessing that Quicktime is the culprit because of the 'Fault Module Name'.
    When I shutdown the Quicktime portion of the program (a subvi that gets called several different times), I perform:
    QTOLibrary.IQTMovie.Stop
    QTOLibrary.IQTMovie.Disconnect
    Set QTOControlLib.IQTControl.URL = [blank]
    QTOControlLib.IQTControl.QuickTimeTerminate
    Destroy QTOControlLib.IQTControl reference
    Destroy QTOLibrary.IQTMovie reference
    Destory QuickTime ActiveX container reference
    Any other properties/methods/combinations/order I should try?  Thanks.
    -Joe

    Hi Joe, 
    Quit LabVIEW shuts down LabVIEW, but does not affect other applications. You need to ensure that your ActiveX references are being closed properly, even if you are quitting LabVIEW.
    A good way to ensure that your references are being closed even when you forcibly exit LabVIEW is to use an event structure. Add a new event to the event structure by right clicking on the default "Timeout" label at the top and selecting "Add Event Case...". Then, under the Event Source, "<Application>", select the event, "Application Instance Close". This event will only execute when you attempt to close your application. Add another "Close Reference" function to the block diagram and wire the reference out output of the Invoke node to the reference input of the Close Reference function. Does this fix your error? 
    Julianne K
    Systems Engineer, Embedded Systems
    Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
    National Instruments

  • How to properly set bind variables

    Dear All,
    I am currently confused about how to properly set my Bind Variables
    I have this view using HR standard schema
    Select *
    from Employees
    where EMPLOYEE_ID = :EMP_IDI somehow see three options on how to use this bind variable in an application module.
    Option 1:
    ViewObjectImpl view = this.getEmployeesView();
    VariableValueManager vm = view.ensureVariableManager();
    vm.setVariableValue("EMP_ID", value);
    view.executeQuery();Option 2:
    ViewObjectImpl view = this.getEmployeesView();
    view.setNamedWhereClauseParam("EMP_ID", value);
    view.executeQuery();Option 3:
    EmployeeViewImpl empView =this.getEmployeesView();
    RowSetIterator it = empView.createRowSetIterator(null);
    empView.setEmployeeId(value);
    empView.executeQuery();Question is which is which and what should I use?
    JDEV 11G PS3

    I use is this
    DCIteratorBinding iteratorStatus = Util.getIterator("NameIterator");
    operationBinding.execute();
    Util is reserved in a class.
    public static DCIteratorBinding getIterator(String iteratorName){
    return getDCBindings().findIteratorBinding(iteratorName);
    }

  • How to properly disconnect a Mini Display Port (MDP) from a Macbook Pro 2012, 1,9?

    Hello:
    I was wondering if any Macxperts out there had any idea on how to properly disconnect a MDP Thunderbolt Cable from a 2012 1,9 Gen. Macbook Pro. From my experience with older Macbooks the command was "Command + F7" or something of the sort.
    On my Macbook Pro 2012, there is no such button or commend to properly disconnect the plug; as if one were to disconnect or "eject" an external HD. I have read some articles on Google that some people just disconnect the plug and that action is sufice to disconnect an external video projection (Ex: Flat Screen Samsung).
    Can a Macxpert or Genius comment on this piece of information? I would really apprecite some light shed on this situation. I just don't see unpluggin a cable connected to a video source enough to properly shut off a connection with out damaging the Macbook Pro's video card.
    Thanks
    A

    Hello, Niel:
    I just answer my own question. Forgive me but I am not up-to-date on the techlingo (Hot Swappable) but I just googled the term and found my answer.
    Thanks again.
    Best,
    A

  • How to find classtype and class for a material.

    Hi,
    How to find classtype and class for a material.
    which table contains this data.
    Thanks
    Kiran

    Hi Kiran,
    Check below sample code. Use this BAPI which will give all info about the class for the material.
      DATA:      l_objectkey_imp    TYPE bapi1003_key-object
                                         VALUE IS INITIAL.
      CONSTANTS: lc_objecttable_imp TYPE bapi1003_key-objecttable
                                         VALUE 'MARA',
                 lc_classtype_imp   TYPE bapi1003_key-classtype
                                         VALUE '001',
                 lc_freight_class   TYPE bapi1003_alloc_list-classnum
                                         VALUE 'FREIGHT_CLASS',
                 lc_e               TYPE bapiret2-type VALUE 'E',
                 lc_p(1)            TYPE c             VALUE 'P',
                 lc_m(1)            TYPE c             VALUE 'M'.
      SORT i_deliverydata BY vbeln posnr matnr.
      CLEAR wa_deliverydata.
      LOOP AT i_deliverydata INTO wa_deliverydata.
        REFRESH: i_alloclist[],
                 i_return[].
        CLEAR:   l_objectkey_imp.
        l_objectkey_imp = wa_deliverydata-matnr.
    *Get classes and characteristics
        CALL FUNCTION 'BAPI_OBJCL_GETCLASSES'
          EXPORTING
            objectkey_imp         = l_objectkey_imp
            objecttable_imp       = lc_objecttable_imp
            classtype_imp         = lc_classtype_imp
    *   READ_VALUATIONS       =
            keydate               = sy-datum
            language              = sy-langu
          TABLES
            alloclist             = i_alloclist
    *   ALLOCVALUESCHAR       =
    *   ALLOCVALUESCURR       =
    *   ALLOCVALUESNUM        =
            return                = i_return
    Thanks,
    Vinod.

  • How can I hide the class file ??

    Hi !
    I has a question, when i write a program of Java, then use the command "javac" to compiler to class file for other people using, but the class file can be disassembled and convert to source code. How can I hide the class file and let people can not disassemble, or can not see the source code. Thinks

    See these....
    http://www.saffeine.com/
    http://www.jarsafe.com/
    I recently read this. This will help you.
    http://developer.java.sun.com/developer/qow/archive/160/index.jsp
    Enojy....
    Rajesh

  • How can I convert a class file to Exe file

    hai
    How can I convert a class file to Exe file

    Please search the forums before asking questions - this has been answered hundreds (really!) of times.

  • How to use the different class for each screen as well as function.

    Hi Experts,
    How to use the different class for each screen as well as function.
    With BestRegards,
    M.Thippa Reddy.

    Hi ThippaReddy,
    see this sample code
    Public Class ClsMenInBlack
    #Region "Declarations"
        'Class objects
        'UI and Di objects
        Dim objForm As SAPbouiCOM.Form
        'Variables
        Dim strQuery As String
    #End Region
    #Region "Methods"
        Private Function GeRate() As Double
                Return Double
        End Function
    #End Region
    Public Sub SBO_Appln_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)
            If pVal.BeforeAction = True Then
                If pVal.MenuUID = "ENV_Menu_MIB" Then
                End If
            Else ' Before Action False
                End If
        End Sub
    #End Region
    End Class
    End Class
    Rgds
    Micheal
    Vasu Anna Regional Feeling a???? Just Kidding
    Edited by: micheal willis on Jul 27, 2009 5:49 PM
    Edited by: micheal willis on Jul 27, 2009 5:50 PM

  • How to use the implementation class in propetty pallete

    Hi,
    I am using forms 10g....I have to insert horizontal scroll bar in text item..
    I have only class files instead of jar files ...how cani place the class file instead of jar file...
    How to use the implementation class in property palette to display the PJC
    Thanks,
    Ansaf.

    The Implementation Class must reflect the full name of the class. For instance, if the full class name is : xx.yyy.zz.class_name, then put this in the Implementation Class property of the corresponding item.
    Also, the class must be stored in the equivalent directory structure, so that, in my example: <DEV_HOME>/forms/java/xx/yyy/zz
    Francois

  • Than how can i get java class by using it's class file?

    Hi
    After compilation of a java program, it creates a class file.
    After getting class file suppose class file has been deleted.
    Than how can i get java class by using it's class file?
    Thanks in advance.

    get a decompiler and run your class file through it--I'll assume you want the source code back and that you are not trying to recover a missing class file by attempting to use the class file that is missing--if it's missing, then I've not a clue on how to get it back by using what is already missing.
    BTW: many of your compilers have source control--if it does, just restore your missing file.

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How to implement a java class in my form .

    Hi All ,
    I'm trying to create a Button or a Bean Area Item and Implement a class to it on the ( IMPLEMENTATION CLASS ) property such as ( oracle.forms.demos.RoundedButton ) class . but it doesn't work ... please tell me how to implement such a class to my button .
    Thanx a lot for your help.
    AIN
    null

    hi [email protected]
    tell me my friend .. how can i extend
    the standard Forms button in Java ? ... what is the tool for that ... can you explain more please .. or can you give me a full example ... i don't have any expereience on that .. i'm waiting for your reply .
    Thanx a lot for your cooperation .
    Ali
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by [email protected]:
    Henrik, the Java importer lets you call Java classes on the app server side - I think what Ali is trying to do is integrate on the client side.
    If you want to add your own button then if you extend the standard Forms button in Java and then use this class name in the implementation class property then the Java for your button will be used instead of the standard Forms button. And since it has extended the basic Forms button it has all the standard button functionality.
    There is a white paper on OTN about this and we have created a new white paper which will be out in a couple of months (I think).
    Regards
    Grant Ronald<HR></BLOCKQUOTE>
    null

  • How to load a java class at server start-up

    Hi,
    I have one custome java class that is being referenced by all the applications deployed in OC4J container. How can I load that class automatically and be evailable in the path at server start-up time. Is there an option available to give the class name that also gets loaded automatically.
    Thanks

    To me, you have two mixed issues.
    1. OC4J supports a startup/shutdown model where a named class will be invoked when the container is started (or stopped).
    This is described in the doc here:
    http://download-west.oracle.com/docs/cd/B32110_01/web.1013/b28952/startclas.htm#CIHECEIB
    Note that this specifically calls the methods that are implemented from the respective OC4JShutdown and OC4JStartup interfaces -- the class that is instantiated and called here is not available to all other applications by default. This is more to suit the need where something needs to be done when the container is started/stopped.
    2 The next option is where you just want to make a class available to all applications deployed to the container. For this we provide the shared-library mechanism. Using this you can either make use of the implicit global.libraries shared-lib in which you simply drop JAR files into the j2ee/home/applib directory whereupon the classes will become available by default to all applications. Or you can choose to install a shared-library that contains your specific classes (in a JAR file) and then import that into the default application whereupon the configuration will be inherited by all deployed applications.
    cheers
    -steve-

  • How to use a java class in difference project under a same workspace!

    Hi, there:
    I have a problem. I want to reuse a java class which is located in another project of the same workspace. I do not know how to set the two project setting or how to import the java class. I deeply appreciate.
    Sheng-He

    include it as a library
    open project settings goto libraries and simply add your class

  • How to import  my own class in jsp file

    I have a jsp file in jsp\ directory and a class in web-inf\classes\ directory. How do I import the class in jsp so i can use it in my jsp file. Thanks,

    This is your lucky day, wennie.
    The correct forum to post this is:
    [http://forums.sun.com/forum.jspa?forumID=45]

Maybe you are looking for