On 7/16/07, Ari Brown <ari / aribrown.com> wrote:
> On Jul 16, 2007, at 5:30 PM, dtuttle1 / gmail.com wrote:
>
> > Hi - I have a memory and cpu-constrained embedded app. There's a long-
> > running loop with a local object (buffer) which eats up memory. A
> > GC.start on every iteration will reclaim it, but that eats the cpu.
> >
> > Is there a way to deallocate the memory used by the temporary objects?
> >
> > file = File.new file_path
> > while buffer = file.read(512)
> >   stream_host_connection.write buffer
> >   stream_host_connection.flush
> >   # GC.start - too expensive
> > end
>
> Unfortunately, I don't know how to do it. If I did, I would include
> it in every single one of my programs. But you should have an extra
> '=' after buffer. It should read...
> ...
> while buffer == file.read(512)

No, Ari.  I think you misread the program.  There is an assignment to
buffer, not a comparison.  The while loop will exit when
file.read(512) returns nil.  I know why you thought it was a
comparison, though.

Todd