jeteve has asked for the wisdom of the Perl Monks concerning the following question:
I've got a problem of collision when I use memoize on an object method.
For instance if I write:package Foo; sub new{ bless { a => undef } , shift ;} memoize('bar'); sub bar{shift->{'a'} ;}
Then when I build a lot of instances of Foo, the bar method starts to behave as they are collisions between object addresses.
I believe this is due to the fact memoize uses a string version of the function arguments, and that the first argument here is something like Foo==HASH(0x8759090) . After a lot of creation/destroy of instance, the garbage collection starts to recycle memory addresses and memoize starts to make your function return phantom values.
Is there a recipe to avoid that ? Should I overload the quote operator and give a unique id to each instance of foo ?
Cheers !
-- Jerome
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memoize collision with objects
by almut (Canon) on Nov 12, 2008 at 12:09 UTC | |
by jeteve (Pilgrim) on Nov 12, 2008 at 12:37 UTC | |
|
Re: Memoize collision with objects
by fmerges (Chaplain) on Nov 12, 2008 at 12:22 UTC | |
|
Re: Memoize collision with objects
by JavaFan (Canon) on Nov 12, 2008 at 13:42 UTC |