You can't "force", because this only happens when you don't need any more the object! In other words, the garbage-collect only happens when the variable that holds the object goes out! To do that just rewrite the variable:
undef $obj ; ## or: $obj = undef ; ## or: $obj = 123 ;
But if you have another variable with the same content of $obj the garbage-collect doesn't happens!

Some tests for DESTROY:

## 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.
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.