GC

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

GC

Gergely BOROMISSZA

Hi!

I have some questions about Lua GC.

As I can see Lua doesn’t free up memory by garbage collecting, just marks it.

Should I really call collectgarbage with parameter “collect” to do this manually or with parameter “step” continuously?

Is there any possibility to do this automatically perhaps parameterized with a memory limit?

Thx

Bleki

Kind regards,

Gergely BOROMISSZA
Developer

T: +36 (1) 872-0000
F: +36 (1) 872-0100
E: [hidden email]

 
Nav N Go Kft.

Bérc u. 23.

H-1016 Budapest

Hungary

 

Nav N Go stands for innovative software for satellite navigation, mobile applications and content on a variety of platforms, enhanced by updates and online services delivered via www.naviextras.com. Find out more about us at www.navngo.com. 

This message, including attachments, is confidential and may be privileged. If you are not an intended recipient, please notify the sender then delete and destroy the original message and all copies. You should not copy, forward and/or disclose this message, in whole or in part, without permission of the sender.

 

Reply | Threaded
Open this post in threaded view
|

Re: GC

Rob Kendrick
On Tue, 5 May 2009 16:52:25 +0200
Gergely BOROMISSZA <[hidden email]> wrote:

> I have some questions about Lua GC.
> As I can see Lua doesn't free up memory by garbage collecting, just
> marks it.

Lua uses a system called mark and sweep.  It will free memory without
you touching anything at all.

> Should I really call collectgarbage with parameter
> "collect" to do this manually or with parameter "step" continuously?
> Is there any possibility to do this automatically perhaps
> parameterized with a memory limit?

The manual is an excellent place to start;

http://www.lua.org/manual/5.1/manual.html#pdf-collectgarbage (from Lua)
http://www.lua.org/manual/5.1/manual.html#lua_gc (from C)

B.
Reply | Threaded
Open this post in threaded view
|

RE: GC

Gergely BOROMISSZA
I've already read the manual but my __gc function was only called when I quit the program or when I call collectgarbage manually. So there was a plenty waste of memory which was not freed.
Bleki



Nav N Go Kft.
Bérc u. 23.
H-1016 Budapest
Hungary

Nav N Go stands for innovative software for satellite navigation, mobile applications and content on a variety of platforms, enhanced by updates and online services delivered via http://www.naviextras.com/. Find out more about us at http://www.navngo.com/.
This message, including attachments, is confidential and may be privileged. If you are not an intended recipient, please notify the sender then delete and destroy the original message and all copies. You should not copy, forward and/or disclose this message, in whole or in part, without permission of the sender.


From: [hidden email] [mailto:[hidden email]] On Behalf Of Rob Kendrick
Sent: 2009. május 5. 17:19
To: [hidden email]
Subject: Re: GC

On Tue, 5 May 2009 16:52:25 +0200
Gergely BOROMISSZA <[hidden email]> wrote:

> I have some questions about Lua GC.
> As I can see Lua doesn't free up memory by garbage collecting, just
> marks it.

Lua uses a system called mark and sweep.  It will free memory without
you touching anything at all.

> Should I really call collectgarbage with parameter
> "collect" to do this manually or with parameter "step" continuously?
> Is there any possibility to do this automatically perhaps
> parameterized with a memory limit?

The manual is an excellent place to start;

http://www.lua.org/manual/5.1/manual.html#pdf-collectgarbage (from Lua)
http://www.lua.org/manual/5.1/manual.html#lua_gc (from C)

B.

Reply | Threaded
Open this post in threaded view
|

Re: GC

Javier Guerra Giraldez
On Tue, May 5, 2009 at 10:27 AM, Gergely BOROMISSZA
<[hidden email]> wrote:
> I've already read the manual but my __gc function was only called when I quit the program or when I call collectgarbage manually. So there was a plenty waste of memory which was not freed.

what happened was probably that the GC didn't see any need to collect.

Lua only keeps track of the memory used inside Lua.  if your userdata
holds only a pointer, or a small structure with references to bigger
objects, that would be the only size that Lua knows about.

to get better results either put most of your object's data inside the
userdata, or add some close() method that releases any resource
external to Lua.

--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: GC

Asko Kauppi

I've recently done a C++/Lua binding, which is really simple,  
efficient and I would say elegant.

It is based on a customized C++ 'new' operator, so pushing an object  
is done as:

        myobj *m= new(L) myobj();

        or if the C side does not need that object, just:

        new(L) myobj();

Of course any constructor will be valid (here without parameters).

The object's memory is allocated from Lua stack, and __gc is bound so  
that the C++ delete operator gets called automatically.

I've enjoyed using this mechanism for the customer project, and I can  
ask them to release it (with MIT license) if there is interest on the  
list.

-asko


Javier Guerra kirjoitti 5.5.2009 kello 18:38:

> On Tue, May 5, 2009 at 10:27 AM, Gergely BOROMISSZA
> <[hidden email]> wrote:
>> I've already read the manual but my __gc function was only called  
>> when I quit the program or when I call collectgarbage manually. So  
>> there was a plenty waste of memory which was not freed.
>
> what happened was probably that the GC didn't see any need to collect.
>
> Lua only keeps track of the memory used inside Lua.  if your userdata
> holds only a pointer, or a small structure with references to bigger
> objects, that would be the only size that Lua knows about.
>
> to get better results either put most of your object's data inside the
> userdata, or add some close() method that releases any resource
> external to Lua.
>
> --
> Javier

Reply | Threaded
Open this post in threaded view
|

Re: GC

Javier Guerra Giraldez
On Tue, May 5, 2009 at 12:46 PM, Asko Kauppi <[hidden email]> wrote:
>
> I've recently done a C++/Lua binding, which is really simple, efficient and
> I would say elegant.
>
> It is based on a customized C++ 'new' operator, so pushing an object is done
> as:

sounds neat.  in fact, i'm tempted to use it (or something similar, if
you don't get to release it), breaking my rule of "bindings stink!"

--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: GC

jomclaughlin
In reply to this post by Asko Kauppi
Nice! I would very much like to see it.

thx,
jim

On Tue, May 5, 2009 at 12:46 PM, Asko Kauppi <[hidden email]> wrote:

I've recently done a C++/Lua binding, which is really simple, efficient and I would say elegant.

It is based on a customized C++ 'new' operator, so pushing an object is done as:

       myobj *m= new(L) myobj();

       or if the C side does not need that object, just:

       new(L) myobj();

Of course any constructor will be valid (here without parameters).

The object's memory is allocated from Lua stack, and __gc is bound so that the C++ delete operator gets called automatically.

I've enjoyed using this mechanism for the customer project, and I can ask them to release it (with MIT license) if there is interest on the list.

-asko


Javier Guerra kirjoitti 5.5.2009 kello 18:38:


On Tue, May 5, 2009 at 10:27 AM, Gergely BOROMISSZA
<[hidden email]> wrote:
I've already read the manual but my __gc function was only called when I quit the program or when I call collectgarbage manually. So there was a plenty waste of memory which was not freed.

what happened was probably that the GC didn't see any need to collect.

Lua only keeps track of the memory used inside Lua.  if your userdata
holds only a pointer, or a small structure with references to bigger
objects, that would be the only size that Lua knows about.

to get better results either put most of your object's data inside the
userdata, or add some close() method that releases any resource
external to Lua.

--
Javier