I didn't look at your code, but from the discussion it appears that you're
confusing two different issues: garbage collection and the presence of
elements in the DOM.

Setting a JavaScript variable to null releases any reference that this
specific variable is holding to any object, but it has *no effect* on the
contents of the DOM. If you have an element in the DOM and want to get rid
of it, you need to remove it from the DOM.

Similarly, when you do remove an element from the DOM, it is removed from
the DOM immediately. It doesn't matter that you may have some JavaScript
variable holding a reference to the element - that will not prevent the
element from being removed from the DOM.

Of course holding superfluous references to objects may affect your memory
usage, because those objects can't be garbage collected, but it won't affect
the structure of the DOM or the appearance of the page.

Hopefully this will help focus your debugging efforts...

-Mike

On Tue, Mar 1, 2011 at 11:01 AM, Brian Earwood <[email protected]>wrote:

> Here is my controller class, which I use to create the rotators:
> http://jsfiddle.net/brianearwood/PKrz8/
>
> Basically, I'm over-writing the previous rotator with a new one:
> var rotator = new Rotator(args);
>
> The old Rotator disappears but when I click to advance to the next image,
> two images (one from the old Rotator/image array and one from the new
> Rotator/image array) get added to the DOM and slide in. Seemingly no amount
> of setting the rotator variable or elements inside of the Rotator class to
> null lets the old one get garbage collected.
>
> Brian
>
>
> On Mar 1, 2011, at 1:21 AM, Rob Brackett wrote:
>
> How do you know it is not being garbage collected? If you keep a reference
> to it, it won't be marked as garbage.
>
> How are you trying to "remove" the rotator?
>
> I can also see how you might have two rotators that conflict, since in some
> places you reference the "node" argument that was passed in (via the
> "photoContainer" var) and in some places you just grab the container by ID
> ($('#photo-container.final .outgoing').css(...)). These might not always be
> the same element and if you had two Rotators, they'd both be trying to
> manipulate #photo-container at the same time.
>
> Finally, there are places where you are trying to delete variables declared
> with the var keyword inside a function, e.g:
>
>         var placeFirstImage = function(firstImage) {
>             $('#photo-container').append(firstImage);
>             outgoingImage = photoContainer.children(0);
>             delete placeFirstImage;
>         };
>
>  That actually doesn't work—using the delete operator on variables declared
> this way will always fail. You can read up a bit more on how delete actually
> works here: http://perfectionkills.com/understanding-delete/
>
> Since it's not completely clear exactly what the problem you're seeing is,
> I hope some of this gets you moving in the right direction.
>
> -Rob
>
>
> On Feb 28, 2011, at 10:32 PM, Brian Earwood <[email protected]>
> wrote:
>
> Hi everyone,
>
> I'm having a good bit of trouble removing one of my objects from my site.
>
> I have an image rotator class that gets created every time a visitor wants
> to view a new image gallery. The new one gets created fine but the old one
> never goes away, no matter how many deletes and nulls I set everything to.
>
> I hate to post a whole class to look at but I'm a bit stuck here.
> Could you check out what my Rotator class looks like and let me know if you
> see any glaring errors that would cause it to not be marked for garbage
> collection:
> http://jsfiddle.net/brianearwood/nMurj/
>
> Or if not, I could use some good resources on the matter.
>
> Thanks for you help!
>
> Brian
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> [email protected] <http://www.mail-archive.com/%3Ca%20href=>/'>
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> [email protected]<http://www.mail-archive.com/%3Ca%20href=>
> /'>http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
>
>  --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to