🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Garbage collection?

Started by
6 comments, last by Ranok 24 years, 5 months ago
I have found a website that has source code for a garbage collector and had a few questions about garbage collection in general. 1. Does garbage collection have much of an impact on the performance of a game? 2. If so, do the benefits of using garbage collection outweight the performance impact? 3. How hard is it to convert a standard C or C++ program into using the garbage collector? Edited by - Ranok on 1/25/00 9:56:21 PM
---Ranok---
Advertisement
It sure has a great impact on performance.
The way garbage collection works is like this,
allocate memory, use it, forget about it and wait for the garbage collector to free it.
They work by checking if a block of memory is still being refered, and for it to working efficiently, requires itself to be called frequently(either by placing it in a thread on its own, or somewhere in your framework.
However, this is definately at a cost. Constant calling would require the garbage collector to be constantly active, and might drastically reduce the performance needed for a game.

I wouldn''t recommend ut
While this most likely won''t lead to memory being unused or memory leaks, it will and actually promotes memory fragmentation. If your game is at all data intesive in memory then garbage collection should be forgotten about because of the mentioned disadvantages. If you don''t mind the memory fragmentation *shrug*. Generally I wouldn''t even consider it because it also opens the door to poor programming and poor resource management. Programmers on your team will tend to just allocate stuff and forget about it resulting in a huge memory footprint and potentially sloppy code.

Kressilac
Derek Licciardi (Kressilac)Elysian Productions Inc.
It''s for the reasons listed above that I would say that garbage collection isn''t your best choice for a high performance game.

FYI: Java implements garbage collection.

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com
Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
1. Garbage collection in addition to the other points mentioned, will also louse up your L2 cache when it does its scans.

2. I''m all for garbage collection techniques used to detect memory leaks during a debug build. If you need garbage collection in a release build for a C/C++ program, then the program shouldn''t be shipped.

3. How hard it is to convert your standard C/C++ program depends on your garbage collector. The garbage collector/leak detection library I use integrates seamlessly. Some garbage collection libraries will make you use GC_malloc versus malloc, and other semantic weirdness.
Thanks for all of your posts; from what has been mentioned from these posts, I think I will scrap using garbage collection in the final product and will only use it for memory leak detection. Once again thank you for your insights.
---Ranok---
Actually I wouldn''t even recommend garbage collection for debug purpose. Or maybe I misinterpretaed the meaning.

I personally create memory function wrappers(actually more like macros) and call them.
In these wrappers(debug mode) I log each memory allocation.
I remove each log entry when I release each memory allocation.
Upon program destruction, I release all unreleased memory, and print out all allocation where it wasn''t released.
Actually some garbage collectors will tell you when the memory is orphaned which can be useful when debugging. If you have the logging function hooked up to a function with just an INT 3 instruction, it''ll give you an insto-zoom to your memory leak. Of course, some work just like your leak detection scheme, so the trick is finding the right libraries.

This topic is closed to new replies.

Advertisement