4 Replies Latest reply on Aug 18, 2009 7:46 AM by _CoreDragon

    Destructors - how to emulate

    _CoreDragon

      I want to call a javascript function when objects get destroyed. I thought I could do this by overriding the destructor method...only to find out action script 3.0 doesn't have them. Any one have any idea how I can do this?

       

      Thanks for your answers

        • 1. Re: Destructors - how to emulate
          Flex harUI Adobe Employee

          I think most folks build in their own reference counting scheme.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          1 person found this helpful
          • 2. Re: Destructors - how to emulate
            _CoreDragon Level 1

            Hi Alex,

             

            Thanks for your reply.

             

            I see. How would I do this? I mean, if I assign an object to something, the reference count of that object should increase by 1..but I don't think I can capture the assigning event. If you could point me to some resource on how this can be done that would be very helpful. Thanks again

            • 3. Re: Destructors - how to emulate
              Flex harUI Adobe Employee

              Every time you assign the object you also call addRef

              Every time you unassign the object you call removeRef and check to see if refCount hits 0.

               

              It is a lot of work, but not any more than knowing when to call delete in C++

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              1 person found this helpful
              • 4. Re: Destructors - how to emulate
                _CoreDragon Level 1

                Hi Alex,

                 

                Thanks again for your response. I am writing a library that users would use to work with our framework. I don't think they'll take it well to ask them to call addRef and removeRef each time.

                 

                The real problem I was trying to solve was I have javascript objects and flex objects that reference them. When flex disposes off one of these proxy objects, I wanted to somehow inform javascript of it. So it can clear away the real object.

                 

                I am going to expose a release method in Flex that will release the javascript object. Though this is not foolproof (people can release the object early, or never release it) - this is the easiest way I can think of.

                 

                If anyone has a better idea, please do let me know!