Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: No garbage collection for my-variables

by kyle (Abbot)
on Sep 16, 2008 at 16:07 UTC ( #711728=note: print w/replies, xml ) Need Help??

in reply to Re^3: No garbage collection for my-variables
in thread No garbage collection for my-variables

Oh, I think I see what you're saying now. When the last reference goes out of scope is the only time it gets to make a decision about whether to deallocate the memory used for the variable. We don't necessarily know then whether the variable will be used again or not, or what for, so it's not a very good time to make that decision.

I'm not sure I'm convinced that deallocating would be a bad thing. Obviously, it depends on what the program is doing. I'd be tempted to take some kind of heuristic approach, but even then I'd want to do some testing to find where the cost/benefits are.

  • Comment on Re^4: No garbage collection for my-variables

Replies are listed 'Best First'.
Re^5: No garbage collection for my-variables (possibilities)
by tye (Sage) on Sep 16, 2008 at 21:00 UTC

    But it wouldn't be terribly hard to implement some improvements here.

    Perl could keep a LRU of still-allocated but unused "large" SVs and periodically free ones that haven't been re-used in the last period of time.

    Note that what might look like the easiest "fix", freeing SVs for lexical variables if they are above a certain size, could have serious draw-backs, at least on some systems. Having done something like this on Win32, this can be a great way for heap fragmentation to cause your process to run out of virtual memory. Perhaps most other systems have smarter malloc()s and so aren't susceptible, but I'm not certain of that.

    It also might be tricky to pick the proper parameters for what consistutes "large" and what the right minimum duration should be before the large allocation is declared "unlikely to be re-used" and free()d.

    - tye        

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://711728]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-07-06 06:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found