It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Problem regarding array & garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem regarding array & garbage collector" Watch "Problem regarding array & garbage collector" New topic
Author

Problem regarding array & garbage collector

Rishiraj Bayerd
Greenhorn

Joined: Aug 06, 2007
Posts: 9
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

Joined: Jan 01, 2007
Posts: 368
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


Thanks and Regards
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
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

Joined: Oct 13, 2005
Posts: 39803
    
  28
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

Joined: Oct 13, 2005
Posts: 39803
    
  28
About arrays: if you are feeling brave go through the Java Language Specification, here.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39803
    
  28
In the analogy given in the Java Language Specification chapter I quoted earlier, it most definitely is "public final int length."
 
 
subject: Problem regarding array & garbage collector