But if you have another variable with the same content of $obj the garbage-collect doesn't happens!undef $obj ; ## or: $obj = undef ; ## or: $obj = 123 ;
Some tests for DESTROY:
You asked for a way to free the memory used to hold the images. Don't forget that Perl, and generally any process in most OS, don't return the memory that it uses to the OS! Perl when clean the memory, it just clean it to be reused for new variables in the same process.## This is for the main package, never do that! package main ; sub new { bless( {} , 'main') ;} sub hy { print "HELLO!\n" ;} sub DESTROY { print "DESTROY!\n" ;} my $obj = main->new ; # create the object. my $clone = $obj ; # save it in the clone. Comment this line # to see that the undef $obj works! print ">>$obj\n" ; # print the references. print ">>$clone\n" ; $obj->hy ; # test a method. undef $obj ; # lose the object. print "__END__\n" ; # End point! If you really lose # the object the DESTROY is called # before this print! Test to comment $clone.
Graciliano M. P.
"The creativity is the expression of the liberty".
In reply to Re: Re: DESTROYing an object
by gmpassos
in thread DESTROYing an object
by batkins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |