lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Monday 21 March 2011 15:40:36 Patrick Donnelly wrote:
> On Mon, Mar 21, 2011 at 1:51 PM, Steve Litt <slitt@troubleshooters.com> 
wrote:
> > In the same vain, in C I always free()
> > whatever I malloc(), even though I know the memory will be given back on
> > program termination.
> 
> This isn't really the best (or fair) analogy. Your memory is never
> eventually garbage collected *during* program execution. In contrast,
> the files Lua opens will eventually be garbage collected (and thus
> closed).

Hi Patrick,

You're absolutely right. With malloc() you know exactly when it will be 
garbage collected, whereas with Lua's open files, not so much.

Your use of the word "eventually" is yet another reason to always close. The 
fact that sometimes it might close quickly and others not for a long time 
leads to hard to diagnose intermittent errors.

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt