LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-07-2010, 09:11 AM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Garbage collection in C


I was wondering if it is possible to have a garbage collector in C, and would it be too difficult to create?
 
Old 01-07-2010, 10:02 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,378
Blog Entries: 52

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
It is possible to have garbage collection in C.

There are either general purpose libraries such as the Boehm-Demers-Weiser one, or you can implement something at a higher level (eg by creating your own 'smart' pointers).

Writing a general purpose collector for C is not trivial. You would need a good understanding of how data is arranged in the different segments by the compiler. The use of pointers in C is not particularly constrained, and even the type constraints can be bypassed, which can make it harder to identify which memory is still in use.

There are some advantages to garbage collection, particularly on larger projects. However, if the primary issue is one of memory leakage, it might be better to use one of the many tools such as valgrind that help profile memory use. Manually coding memory allocation/deallocation requires some discipline, but it doesn't require much extra effort.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Garbage Collection Problem in FC8 baddah Fedora 2 06-27-2008 10:08 AM
How Many Kernels Have Garbage Collection? Peatmoss Linux - Newbie 9 12-03-2007 11:15 PM
LXer: Real-time garbage collection with Real-time Java LXer Syndicated Linux News 0 05-05-2007 01:16 PM
Garbage Collection in C : Local variables question duryodhan Programming 13 12-04-2006 08:16 AM
Video garbage only zonder Linux - Newbie 5 07-21-2005 04:37 PM


All times are GMT -5. The time now is 04:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration