English 中文(简体)
What is the best way for debug output for the lua garbage collector?
原标题:

I need a game state object in lua(not c++ or tied to C++) to manage lights, cameras, objects, events from my C++ engine (the lua objects are seperate entities from c++, pretty much just standard lua tables). I am concerned about how the GC is going to act in removing these objects since they are going to be created and removed on the fly. what is the best way to turn on Output for the GC? I have the lua source embedded in my code...

最佳回答

The Lua garbage collector doesn t have any output. You have two choices here.

First, you could provide Lua a custom allocator. This would let you track how and when Lua allocates and deallocates memory. This would tell how how often the GC asked for more memory and how often it frees said memory. You could also add allocation tracking that would let you detect leaked memory at application exit.

Since you have the source, you could also add instrumentation to the Lua garbage collector code directly. It s self contained in lugc.c.

问题回答

Did you read the Lua Manual?

Lua objects are completely hidden from the C++ side so you have to put each Lua object into a special hash table and remove it from there when you destroy the C++ object. If the C++ and Lua objects have the same lifetime you can simply do this code in the ctor/dtor.

If you want some debugging output for the GC i guess you have to add printf lines directly into the lua source code as there is AFAIK no code for this in the standard Lua codebase.





相关问题
GarbageCollector, Dispose or static Methods?

I developed a few classes last month. They grow big (round 30-40 Methods each class). I never take a thought of Memory Leaks, GarbageColletor or something like this (I must say this is my first own ...

Can t free memory of NSData object

i m new to xcode / cocoa and even objective-c thus my question might be stupid. Im trying to write a program that will hash files in a folder. I looked around and found a way to load a file via a ...

Alternative to Java

I need an alternative to Java, because I am working on a genetics-calculation project. It takes a lot of memory and the most of the cpu time. And therefore it won´t work when I deploy it on a server, ...

Question about the garbage collector in .NET (memory leak)

I guess this is very basic but since I m learning .NET by myself, I have to ask this question. I m used to coding in C, where you have to free() everything. In C++/.NET, I have read about the garbage ...

Does garbage collection work with the Go compiler (gc)?

I noticed that garbage collection is not yet implemented in gccgo. http://golang.org/doc/gccgo_install.html#Unimplemented Does the standard Go compiler (gc) support garbage collection yet?

doubts regarding Memory management in .net

I m learning about Memory management in C# from the book "Professional C#" The presence of the garbage collector means that you will usually not worry about objects that you no longer need; ...

热门标签