Skip Menu |
 

This queue is for tickets about the JavaScript CPAN distribution.

Report information
The Basics
Id: 35572
Status: resolved
Priority: 0/
Queue: JavaScript

People
Owner: Nobody in particular
Requestors: CRAKRJACK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.06
Fixed in: 1.07



Subject: Once you bind_object, you can never unbind it or replace the binding
Download (untitled) / with headers
text/plain 439b
When this script is run, it attempts to create 10 objects in the ThisObjectWillNotLeak class. Unfortunately, although it does create 10 objects of this class, only the first one that is bound ever makes it into the JavaScript interpreter. You will see 10 "leaky" objects get passed into JavaScript, but only one "Sealed" object. I also have a feeling that if the "Sealed" objects were all passed into javascript, they would leak as well.
Subject: leaktest.pl
Download leaktest.pl
text/x-perl 1.4k
#!perl use strict; use warnings; use Devel::Leak::Object qw(GLOBAL_bless); use JavaScript qw(:all); { package ThisObjectWillLeak; sub new { my($class, $num) = @_; return bless { n => $num }, $class; } sub whoami { my $self = shift; return "Leaky object #$self->{n}"; } } { package ThisObjectWillNotLeak; sub new { my($class, $num) = @_; return bless { n => $num }, $class; } sub whoami { my $self = shift; return "Sealed object #$self->{n}"; } } our $rt = JavaScript::Runtime->new; our $cx = JavaScript::Context->new($rt); sub dont_leak_an_object { my $sealed = ThisObjectWillNotLeak->new(shift); $cx->bind_object(sealed => $sealed); return; } sub leak_an_object { my $leaky = ThisObjectWillLeak->new(shift); return $leaky; } sub write { my $msg = shift; print "$msg\n"; } foreach my $i ('ThisObjectWillLeak', 'ThisObjectWillNotLeak') { $cx->bind_class( name => $i, constructor => sub {}, methods => { whoami => $i->can('whoami') }, flags => JS_CLASS_NO_INSTANCE, package => $i ); } $cx->bind_function(leak_an_object => \&leak_an_object); $cx->bind_function(dont_leak_an_object => \&dont_leak_an_object); $cx->bind_function(write => \&write); foreach my $i (1 .. 10) { $cx->eval("leaky = leak_an_object($i)"); $cx->eval("dont_leak_an_object($i)"); $cx->eval("write(leaky.whoami())"); $cx->eval("write(sealed.whoami())"); }
Download (untitled) / with headers
text/plain 123b
I just ran a few more tests, bind_value() has this problem as well, *even* when dealing with simple scalars / integers :-(
Subject: Re: [rt.cpan.org #35572] Once you bind_object, you can never unbind it or replace the binding
Date: Thu, 1 May 2008 21:06:30 +0200
To: bug-JavaScript [...] rt.cpan.org
From: Claes Jakobsson <claes [...] versed.se>
Download (untitled) / with headers
text/plain 713b
Hi, On 1 maj 2008, at 20.46, CRAKRJACK via RT wrote: Show quoted text
> > Queue: JavaScript > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35572 > > > I just ran a few more tests, bind_value() has this problem as well, > *even* when dealing with simple scalars / integers :-( >
bind_object (and bind_function) uses bind_value internally so they should both have the same problem. One of the memory leaks has been (the one that causes ThisObjectWillNotLeak 5 has been address in the latest SVN version. I'm not quite sure if I want bind_value just to silently replace a property with a new value or if it should croak and you would have to use unbind_value (function|object as aliases) first. /Claes
Subject: Re: [rt.cpan.org #35572] Once you bind_object, you can never unbind it or replace the binding
Date: Thu, 1 May 2008 13:21:38 -0700
To: Claes Jakobsson via RT <bug-JavaScript [...] rt.cpan.org>
From: Tyler MacDonald <tyler [...] yi.org>
Download (untitled) / with headers
text/plain 570b
Claes Jakobsson via RT <bug-JavaScript@rt.cpan.org> wrote: Show quoted text
> bind_object (and bind_function) uses bind_value internally so they > should both have the same problem. One of the memory leaks has been > (the one that causes ThisObjectWillNotLeak 5 has been address in the > latest SVN version. > > I'm not quite sure if I want bind_value just to silently replace a > property with a new value or if it should croak and you would have to > use unbind_value (function|object as aliases) first.
unbind_value! Can I do that? It's not in the API docs :-) - Tyler
Subject: Re: [rt.cpan.org #35572] Once you bind_object, you can never unbind it or replace the binding
Date: Fri, 2 May 2008 00:14:21 +0200
To: bug-JavaScript [...] rt.cpan.org
From: Claes Jakobsson <claes [...] versed.se>
Download (untitled) / with headers
text/plain 882b
On 2 maj 2008, at 00.09, tyler@yi.org via RT wrote: Show quoted text
> > Queue: JavaScript > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35572 > > > Claes Jakobsson via RT <bug-JavaScript@rt.cpan.org> wrote:
>> bind_object (and bind_function) uses bind_value internally so they >> should both have the same problem. One of the memory leaks has been >> (the one that causes ThisObjectWillNotLeak 5 has been address in the >> latest SVN version. >> >> I'm not quite sure if I want bind_value just to silently replace a >> property with a new value or if it should croak and you would have to >> use unbind_value (function|object as aliases) first.
> > unbind_value! Can I do that? It's not in the API docs :-)
It's not in 1.06 but will be in the next release. If you want it now you'll have to check it out form my repository. svn://svn.surfar.nu/public/JavaScript/trunk /Claes


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.