At long last, HTML-Tree can now use weakrefs.  This means you no longer
need to call "$tree->delete" to prevent memory leaks.

Right now, you can get trial release 4.900 from CPAN:
https://metacpan.org/release/CJM/HTML-Tree-4.900-TRIAL/

I plan to release 5.00 before YAPC::NA, probably on June 12.  (This
would probably be a good subject for a lightning talk, if someone wants
to give it.  I'd do it myself, but I'm not going to be able to make it
to YAPC this year.)

If you're using HTML-Tree, please test your code with the new version now.

While most programs should continue to work fine with this change, it
could break your code.  The one real-world example I've found so far is
pQuery's dom.t.  In pQuery 0.08, it does:

  my @elems = pQuery::DOM->fromHTML('<div>xxx<!-- yyy -->zzz</div>')
                         ->childNodes;
  my $comment = $elems[1];
  is $comment->parentNode->tagName, 'DIV', 'Comment has parentNode';

Notice that it's not saving the result of the fromHTML call; only the
child nodes.  Since children now have only a weak reference to their
parent, the root node is deleted immediately, and $comment->parentNode
is undef.

This can be fixed by saving a reference to the root node:

  my @elems = (my $r = pQuery::DOM
                       ->fromHTML('<div>xxx<!-- yyy -->zzz</div>'))
                       ->childNodes;

As a quick fix for broken code (and to determine whether it's the weak
references that are causing the breakage), you can say:

  use HTML::Element -noweak;

This (globally) disables HTML-Tree's use of weak references.  But this
is just a temporary measure.  You need to fix your code, because this
feature will be going away eventually.

-- 
Chris Madsen                                          p...@cjmweb.net
  --------------------  http://www.cjmweb.net  --------------------

Reply via email to