Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem regarding array & garbage collector

 
Rishiraj Bayerd
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have two question....

1.I want to know how garbage collector works on mutable objects(such
asobject of String & Wrapper class) ?

2.For knowing the length of array, we use array.length.... my quetion is what is length ?

thanks

with regards
Rishi
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.I want to know how garbage collector works on mutable objects(such
asobject of String & Wrapper class) ?


I guess you ment 'immutable' here.

2.For knowing the length of array, we use array.length.... my quetion is what is length ?

You said yourself, its the length of the array
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a serious note, I am also curious to know if immutable objects are treated differently for garbage collection(as stings are maintained in a pool)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, they aren't. All types of object are garbage-collected similarly. Strings have a sort of constant pool for those which exist as literals; since they are in the actual code, they remain "accessible" until the classes they are used in are unloaded (and, I think, until their class loaders are unloaded too).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About arrays: if you are feeling brave go through the Java Language Specification, here.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satya Maheshwari:

You said yourself, its the length of the array

Technically you could consider it a "public final int" field. Not static of course, but it is most certainly public and final - you can't change it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the analogy given in the Java Language Specification chapter I quoted earlier, it most definitely is "public final int length."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic