• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

could anyone please tell me the GC

 
Greenhorn
Posts: 27
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, please help me in solving the Garbage Collection related programs, even when i read K&B book but i still have facing the problems, could anybody tell me to solve, the initial and most common steps to consider in the program. Please reply me as fast, as i need is very urgent
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give any specific code where you are facing problem..like keeping track of how many objects elligible for garbage collection??
try to do some paper work for such type of questions..i mean to keep track of which reference variable is referring to which object..

thanks!
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phani

Here is a good blog on garbage collection.

I hope this will clear your questions.

Murali...
[ July 24, 2007: Message edited by: Murali Kakarla ]
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Garbage Collection problem are more conceptual than theoratical.Just grab the key concepts and try solving the problems.
If fails to solve post it in the forum.
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some points you should keep in mind for gc:
1) finalize method is run only once by JVM on the object next time it becomes eligible for GC JVM doesnot call the finalize again.
2)Java maintain String literal table sso handling string is different from other objects (specially in case of questions like how many objects created and how many of them are eligible for GC)
3)Remember we are talking about the objects and not refrences so track the object and refrence
4)its better you solve problem through object diagram
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One hard coded rule about GC.


" Never ever trust System.gc(). There is only a possibility but not certainty."

 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya its a request to the compiler and its upto the compiler to accept it or not.
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by subodh gupta:
ya its a request to the compiler and its upto the compiler to accept it or not.

Small correction. It' a request to the runtime system, not the compiler.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you been a C user remember that difference betweent the two(Java and C) in relation to GC . In C we don't have GC done implicitly, but we need to GC explicitly. In java it's done by the system , only catch being you have very less or no control over it.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing better than object diagrams.
e.g.
String s1 = new String("Asif");
make a diagram where you make a say circle,put "Asif" in it and make s1 to point to it.
Suppose now you have
String s2 = new String("Garhi");
s1=s2;
just break the arrow (pointing from s1 to "Asif") and make it to point to "Garhi".
Now 2 arrows point to "Garhi" one each from s1 and s2 and nothing points to the "Asif" object.Keep doing this till the end of your program (or till a place where you intend to) and all the circles or objects to which nothing is pointing are all eligible for GC.

It always works for me.
Ranchers .. are there any exceptions to above rule?

[ July 25, 2007: Message edited by: Asif Garhi ]
[ July 25, 2007: Message edited by: Asif Garhi ]
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Murali!!!

The blog was realy gud....!!!
 
phani bhushan reddy
Greenhorn
Posts: 27
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Murali thats a good blog thanks for your reply
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also there is concept of isolated objects which is not understandable..please if anyone can explain with example, it would be great help.

following is the code:
class I {
private I other;
public void other(I i) {other = i;}
}
class J {
private void m1() {
I i1 = new I(), i2 = new I();
I i3 = new I(), i4 = new I();
i1.other(i3); i2.other(i1);
i3.other(i2); i4.other(i4);
}
public static void main (String[] args) {
new J().m1();
}}

Which object is not eligible for garbage collection after method m1 returns?

please explain the flow of this program..
Thanks in advance.

Thanks,
Tashi
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic