Hi again, Been a while since my last post. I have started working heavily with Perl modules...mostly writing custom modules that utilize XML::Simple(). My question is, is there any problems and/or concerns with doing my own memory management with the custom modules? ... i.e. seting unused objects back to undef?

I come from a heavy C/C++ background...thus, there is an inherit "want" to manage this stuff explicitly...

For example...A typical module would get supplied a filename to an XML document file. Then do the following...
- Create and XML::Simple()
- Read in the document.
- Store the elements into a local hash.
- set XML::Simple() stuff = undef; # memory cleanup
A small code snippet looks like the following...

# MAIN PRORGRAM : ... # else { $gtheProcess = undef; $gtheProcess = new Registry ( file => $strDir."/".$strProcess ,verbose => $gblnVerbose ); } <snip> # REGISTRY MODULE : new () # sub new { my $class = shift; my $self = {}; my $theOptions = { @_ }; ....lots of code... if ( exists($self->{file}) ) { my $gxmlFile = $self->{file}; if ( open( ghdlFile, "< $gxmlFile" ) == 1 ) { close ghdlFile; # XML : Create a new XML object... my $gxmlObject = XML::Simple->new(); # OPEN : Open the configuration file... my $gxmlDocument = $gxmlObject->XMLin($gxmlFile); # CAPTURE : Grab all the configuration elements from the f +ile... foreach my $lstrKey (keys (%{$gxmlDocument})) { $self->{$lstrKey} = $gxmlDocument->{$lstrKey}; } # end : foreach # FREE : Free up objects... # $gxmlDocument = undef; $gxmlObject = undef; } # end : if ( open( cfgFH, "< $gxmlConfigFile" ) == 1 ) } # if ( exists($self->{file}) ) return( bless($self, $class) ); } # end : new()
Does Perl like/dislike explicit memory management by setting the above $gxmlDocument and $gxmlObject = undef?

tia,

adym

In reply to Memory Management... by alincoln

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.