1

I have an object:

var myObj = new myAwsumObj();

Now, currently I am deleting it like that:

myObj = undefined;

But that apparently does nothing, since object still exists (I can see that exceptions are being thrown by something that is in the 'external' javascript file that this object is defined in).

How do I clear all this stuff up? Is it possible? Because it seems like myObj is doing very much in this external javascript file, maybe even creating new objects, is it possible to clear all this mess without refactoring this external file?

4
  • You don't get pointers in JavaScript. With objects, you get a reference, but you can't use that reference to destroy the object if there are other variables that also have a reference to the same object. Commented Apr 18, 2013 at 1:27
  • Did you write the code for the myAwsumObj() function? Commented Apr 18, 2013 at 2:10
  • @nnnnnn: If I would, then I wouldn't ask this question. :) Commented Apr 18, 2013 at 2:11
  • @ojek : Try assigning myObj as null i.e. myObj=null; Commented Apr 18, 2013 at 4:04

1 Answer 1

1

Unfortunately, it's not possible. From your description, the object itself seems to be creating references to itself, by adding event handlers, setting timeouts/intervals, ajax callbacks, whatever. Even if you clear all the references to the object created by yourself, you'd still have to clear the references it creates on its own. Only then it would become inactive, unreferenced, and eligible for garbage collection.

But look into its source code, maybe the object provides a "destruct" method to take care of all that mess.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.