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 08-24-2005, 10:11 PM   #1
Garda
Member
 
Registered: May 2005
Distribution: Debian
Posts: 83
Blog Entries: 2

Rep: Reputation: 15
what does garbage collected mean


i've heard of languages that are garbage collected. i think java is an
example. what does this mean
 
Old 08-24-2005, 10:15 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
its a method to reclaim memory, from unused objects.. more or less.
read this
java has automatic collection, c++ might be manual... im not positive, i dont use c++, only java.
 
Old 08-25-2005, 12:38 AM   #3
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
C / C++ certainly do not have Garbage Collection.

Ass far as I know, it is to free up memory on the heap from unused objects. I think it also has something to do with pointers - If you dynamically allocate an array using malloc or calloc, you must remember to use free to release the memory.

Java does have automatic garbage collection - when there are no references to any objects, Java knows that it can safely remove these from memory, and will do so when it feels like it.

I hope this helps
--Ian
 
Old 08-25-2005, 01:54 AM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
In C++ this function would cause a memory leak:

Code:
void memoryleak()
{
    string * s = new string;
    s = "Hello World";
    cout << s << endl;
}
It generates a memory leak because the string "Hello World" is allocated on the heap. Pointer 's' is created on the stack when the function is called. s points to "Hello World", but s is lost when the function returns. Basically s was the last reference to this heap memory, and now it wont be found and a memory leak occurs. Java would notice this lack of references and perform the cleanup itself, probably by calling the string destructor when all references are destroyed.
 
  


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
2Wire Garbage axessterminated Linux - Hardware 3 10-07-2005 11:47 AM
Video garbage only zonder Linux - Newbie 5 07-21-2005 03:37 PM
Printers printing garbage? inkysplat Linux - Hardware 1 11-03-2003 02:27 PM
Printing garbage sakkie Slackware 1 09-19-2003 12:14 PM
xv grab garbage kramtoad Linux - Software 0 08-23-2003 07:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:56 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
Open Source Consulting | Domain Registration