Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have plotted a comparative graph with GD::Graph which is the output of a CGI script displayed within a HTML form. Every time the script is executed, the graph is (re)generated.

It appears that values of the graph double upon execution which makes me surmise that the underlying object is not released upon termination of the script.

Is there a way to manually force the instance of GD::Graph to be garbage collected at the end of the script?

Replies are listed 'Best First'.
Re: releasing GD in CGI script?
by moritz (Cardinal) on Dec 17, 2008 at 23:42 UTC
    It appears that values of the graph double upon execution which makes me surmise that the underlying object is not released upon termination of the script.

    If you use normal CGI scripts, and not something like mod_perl or FastCGI, that's virtually impossible. The memory is cleared by the operating system when the script terminates, Perl objects can't survive that.

      You're correct. I should have been more explicit. This is a ModPerl script

      Is there a way to force memory cleaning?

        Usually you don't need this. Just use strict; use warnings; and make the variable that holds the GD object a lexical variable, then it will be cleaned automatically on scope exit.

        If you can't figure it out, you can still say undef $gd;

Re: releasing GD in CGI script?
by zentara (Cardinal) on Dec 18, 2008 at 19:28 UTC
    Read "perldoc -q clear" for the first entry, "How do I clear a package?".

    I'm not really a human, but I play one on earth Remember How Lucky You Are