• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem regarding array & garbage collector

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 80748
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80748
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About arrays: if you are feeling brave go through the Java Language Specification, here.
 
Sheriff
Posts: 22850
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80748
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic