[Catalyst] Storing $c leaks memory?

2007-08-23 Thread Tobias Kremer
While hunting down some memory leaks in my application I found that it's
generally a bad idea to store $c in a class as this never gets cleared up
completely, is that correct?

I'm also doing things like this which seem to cause major leaks:

$foo->bar( coderef => sub { return $c->forward( '/someaction' ) } );

While I can imagine that a closure like that can cause trouble I don't see why
the following is leaking memory, too:

in a Controller:

my $foo = Foo->new( $c );

in Foo.pm:

sub new {
  my( $class, $c ) = @_;
  my $self = {};
  $self->{ '_c' } = $c;
  bless $self, $class;
}

Maybe somebody can shed some light on this?! Is it possible (and sensible) to
weaken $c before storing it?

Thanks a lot!

--Tobias

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Storing $c leaks memory?

2007-08-23 Thread Christopher H. Laco
Tobias Kremer wrote:
> While hunting down some memory leaks in my application I found that it's
> generally a bad idea to store $c in a class as this never gets cleared up
> completely, is that correct?
> 

I'd wager circular reference issue. Take a look into ACCEPT_CONTEXT
controller.

In short, if you're going to store a copy of $c in your classes, weaken
them first using Scalar::Util::weaken

Of course, I could be full of it. :-)

-=Chris



signature.asc
Description: OpenPGP digital signature
___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/