From: "Martin Moss" <[EMAIL PROTECTED]> To: "Perl-Win32-Users \(E-mail\)" <[EMAIL PROTECTED]>, "Perl-Unix-Users \(E-mail\)" <[EMAIL PROTECTED]> Subject: [Perl-unix-users] memory issues Date sent: Wed, 2 Apr 2003 12:12:18 +0100
> Secure FTPAll, > > I was wondering if I could get clarification on something. > I have a class object called $x. > > What I want to do is pass this $x into objects $y & $z, and store it > internally Thus:- > > $y->{x}=$x; > $z->{x}=$x; > > This Is ok, and shouldn't cause any problems. However what happens if, > in $y I have a method which does this:- > > sub method > { > my $y=shift; > my $z=MYMod::Z->new(x=>$y->{x}); > > $y->{z}=$z; > > } > > I am concerned I'm creating some sort of memory leak? Did you create a loop between the objects? (A points to B, B points to C and C points to A) If you did not, you are safe. If you did you'll have to either 1) break the loop explicitely when you want to get rid of the objects or 2) use Scalar::Utils and weaken some of the references. Weak reference is a reference that doesn't increase the reference- count. That is if there are only weak references to an object it may be destroyed/garbage collected. Of course in this case you have to be a bit carefull. I would probably go with the weak references. Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs