Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
For the most part, Perl's garbage collection will handle discarding variables and cleaning up for you automatically. As you suggest, if you're mindful of the imminenet death of a variable scope, don't worry about calling undef.

With that in mind, there are a couple of places where you might want to massage things by hand.

  • When you have a circular data structure, like a doubly linked list or some other monstrosity. As the gc works by reference counting, if you have two objects that only point to each other, they'll still stick around. Break the links or undefine one or both objects.
  • When you won't be leaving the scope for a while, but you have an item using lots of memory. One example would be performing some sort of transformation on a large data file. If you must do it all in memory (for speed reasons) but you copy it from one scalar to another, undef the first scalar as soon as possible.
The first is the only one I'd really worry about -- with some thoughtful programming, the second may never come up. I really don't worry about it much, as wise coding tends to minimize memory usage anyway.

In reply to Re: Why Thrash Memory? by chromatic
in thread Why Thrash Memory? by Kozz

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2022-12-07 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?