You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Gary Hirschhorn <gh...@fetch.com> on 2009/04/22 17:34:46 UTC

Node without parent eligible for garbage collection or pinned by Document?

If I create new Nodes via Node.createClone() or Document.newElement(), I
now have a Node that belongs to a Document, but has no parent Node. With
regards to garbage collection, if this new Node is no longer reachable
by the objects in my code, is it eligible for garbage collection, or is
there some internal pointer from Document that will pin this Node in
memory until the Document is garbage collected?  

 

Thanks,
Gary


RE: Node without parent eligible for garbage collection or pinned by Document?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Gary,

"Gary Hirschhorn" <gh...@fetch.com> wrote on 04/22/2009 11:52:28 AM:

> Thanks.  In the case of Node.createClone(), I could see how back-
> pointers could be a problem (although I think the documentation says
> everything should be a copy when the clone is complete.).  However,
> for Document.newElement(), assuming we don?t use setUserData() or
> similar methods, are there any back pointers to other nodes in the
document?

No and there shouldn't be any for cloneNode() either. Keep in mind that I'm
only talking about what Xerces does. One could imagine other
implementations of cloneNode() which do the copy at the point you actually
access the cloned node, meaning it would need links back to the data of the
original node so that it could do the expansion later.

> From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com]
> Sent: Wednesday, April 22, 2009 8:49 AM
> To: j-users@xerces.apache.org
> Subject: Re: Node without parent eligible for garbage collection or
> pinned by Document?
>
> Hi Gary,
>
> They will usually be eligible for garbage collection, however there
> are some operations (e.g. setUserData()) which will pin down the
> memory even if the Node is otherwise orphaned. Basically there are a
> bunch of structures in the Document node impl which might have back-
> pointers to other nodes in the document that can't be cleared until
> the application no longer has any references to those nodes. Future
> versions of Xerces will use SoftReferences and WeakReferences in
> these places so such nodes can be garbage collected earlier.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Gary Hirschhorn" <gh...@fetch.com> wrote on 04/22/2009 11:34:46
AM:
>
> > If I create new Nodes via Node.createClone() or Document.
> > newElement(), I now have a Node that belongs to a Document, but has
> > no parent Node. With regards to garbage collection, if this new Node
> > is no longer reachable by the objects in my code, is it eligible for
> > garbage collection, or is there some internal pointer from Document
> > that will pin this Node in memory until the Document is garbage
collected?
> >
> > Thanks,
> > Gary

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

RE: Node without parent eligible for garbage collection or pinned by Document?

Posted by Gary Hirschhorn <gh...@fetch.com>.
Thanks.  In the case of Node.createClone(), I could see how
back-pointers could be a problem (although I think the documentation
says everything should be a copy when the clone is complete.).  However,
for Document.newElement(), assuming we don't use setUserData() or
similar methods, are there any back pointers to other nodes in the
document?

 

From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Wednesday, April 22, 2009 8:49 AM
To: j-users@xerces.apache.org
Subject: Re: Node without parent eligible for garbage collection or
pinned by Document?

 

Hi Gary,

They will usually be eligible for garbage collection, however there are
some operations (e.g. setUserData()) which will pin down the memory even
if the Node is otherwise orphaned. Basically there are a bunch of
structures in the Document node impl which might have back-pointers to
other nodes in the document that can't be cleared until the application
no longer has any references to those nodes. Future versions of Xerces
will use SoftReferences and WeakReferences in these places so such nodes
can be garbage collected earlier.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Gary Hirschhorn" <gh...@fetch.com> wrote on 04/22/2009 11:34:46
AM:

> If I create new Nodes via Node.createClone() or Document.
> newElement(), I now have a Node that belongs to a Document, but has 
> no parent Node. With regards to garbage collection, if this new Node
> is no longer reachable by the objects in my code, is it eligible for
> garbage collection, or is there some internal pointer from Document 
> that will pin this Node in memory until the Document is garbage
collected?  
>  
> Thanks,
> Gary


Re: Node without parent eligible for garbage collection or pinned by Document?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Gary,

They will usually be eligible for garbage collection, however there are
some operations (e.g. setUserData()) which will pin down the memory even if
the Node is otherwise orphaned. Basically there are a bunch of structures
in the Document node impl which might have back-pointers to other nodes in
the document that can't be cleared until the application no longer has any
references to those nodes. Future versions of Xerces will use
SoftReferences and WeakReferences in these places so such nodes can be
garbage collected earlier.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Gary Hirschhorn" <gh...@fetch.com> wrote on 04/22/2009 11:34:46 AM:

> If I create new Nodes via Node.createClone() or Document.
> newElement(), I now have a Node that belongs to a Document, but has
> no parent Node. With regards to garbage collection, if this new Node
> is no longer reachable by the objects in my code, is it eligible for
> garbage collection, or is there some internal pointer from Document
> that will pin this Node in memory until the Document is garbage
collected?
>
> Thanks,
> Gary