• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Garbage Collection

 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3. class Dozens {
4. int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
5. }
6.
7. public class Eggs {
8. public static void main(String[] args) {
9. Dozens [] da = new Dozens[3];
10. da[0] = new Dozens();
11. Dozens d = new Dozens();
12. da[1] = d;
13. d = null;
14. da[1]= null;
15. // do stuff
16.
17. }
18.
19. }
20.

PLEASE READ CAREFULLY...THANKS

Question: How many objects are created within the "main() method",
and how many of those are eligible for garbage collection when line
14 is reached?¿?

Answer: five objects created and two objects eligible for garbage
collection. (REMEMBER "WITHIN THE MAIN METHOD").

The above answer would be correct if:
Dozens [] da refers to an object of type "Dozens array".

And if:
each newly created Dozen object has its own int array Object, meaning:
da[0] = new Dozens(); are two objects!!

1. Dozens Object.
2. int[] array Object

And, does this have anything to do with the "HAS-A" theory?¿?

I will be greatfull if anyone can clearify my doubts.

 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags to write codes. Thanks
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you are saying is true. The explaination is perfect. Yes It is because of the Has-A relationship between Dozen and the int array.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neha Daga wrote:Please use code tags to write codes. Thanks


Thanks...I understand you and would appreciate better if after correcting
me "on quote tags", you end it up clearifying my doubts okay?¿? Thanks.
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well I did that.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neha Daga wrote:well I did that.


Thanks body...
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please => SearchFirst <= and => UseCodeTags <=. Discussed recently!
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ikpefua, there are a few guidelines that you should keep in mind while posting on javaranch. Using Code Tags is one of them. When you use code tags around your code, the code is easier to read. Also please mention the source when you post a mock exam question...
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your information/advise, as you can see Im completely new in this game, such info would help me construct better posts in future. Thanks once again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!