[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is breaking out of io.lines(file) safe?
- From: Steve Litt <slitt@...>
- Date: Mon, 21 Mar 2011 16:05:05 -0400
On Monday 21 March 2011 15:40:36 Patrick Donnelly wrote:
> On Mon, Mar 21, 2011 at 1:51 PM, Steve Litt <email@example.com>
> > 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
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.
Recession Relief Package