lua-users home
lua-l archive

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


On Thu, Sep 2, 2010 at 4:09 PM, Jonathan Castello <twisolar@gmail.com> wrote:
> On Thu, Sep 2, 2010 at 1:03 PM, Sylvain Fabre <sylvain.fabre@inpixal.com> wrote:
>>  Yes of course :) All our objects have a __gc metamethod implemented !
>> But the core issue is that for each object allocated internally, onlye 4
>> bytes/8bytes are seen from the LUA garbage collector... But internally,
>> megaoctets are allocated...
>> Hence, the garbage collector does not trigger "properly", and we ran out of
>> memory.
>
> What if you allocate the entire space required by your object as a
> userdatum, and use placement new to initialize it into the space Lua
> allocated for you? Then you're not using a pointer, you're using the
> whole object.


What happens when you resize an image?  You need to allocate more
memory.  You can't modify all the Lua references to the old image, so
you need the Lua refs to be shallow pointers to the real data.  And
allocating the real data as userdata too, and then hanging a reference
to it, gets to be a pain.  You could make all operations return new
images, but that's quite inefficient.

I was able to work around the problem with explicit close() methods,
and also ended up not creating many images, but that's not viable for
everyone.

I think many languages offer some sort of "inflate" interface to the
garbage collector to either specify the real size of an object, or at
least indicate overall memory pressure.