Results 1 to 3 of 3
Like Tree3Likes
  • 2 Post By jim829
  • 1 Post By Tolls

Thread: Reference Type Variables

  1. #1
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default Reference Type Variables

    " Java does not allow any arithmetic to be done with references. This, coupled with Java's lack of any way to explicitly deallocate the storage used by reference type values, guarantees that a reference can never point to an illegal address."

    I have two questions and I will be very grateful if somebody can clarify me about them.
    1. Java's lack of way to explicitly deallocate the storage used by reference type values! But we can assign NULL to the reference variables to deallocate them??
    2. How do these two things (that arithmetic cant be performed on reference variables and there is no explicit way to deallocate them assure that they can never point to an illegal address??


    Thank you very much in advance.
    Don't forget to smile :-)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,600
    Rep Power
    5

    Default Re: Reference Type Variables

    Well, I am not 100% certain. But Java does not provide the programmer any way of directly freeing memory like some low level functions in the C programming world. So if no method exists, you can't pass a bad address to it. As far as math on references is concerned, I recall in C that if you had a pointer, ptr, and added some constant to it, you could them reference that new address with *ptr. You can't do that in Java. So you can't alter the address of a reference to some illegal location. The JVM and the garbarge collector take care of freeing up memory.

    Regards,
    Jim
    Last edited by jim829; 10-15-2013 at 03:08 PM.
    Tolls and Nazneen Ali like this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Reference Type Variables

    Quote Originally Posted by Nazneen Ali View Post
    But we can assign NULL to the reference variables to deallocate them??
    That doesn't deallocate any memory.
    It just means that particular reference variable is no longer pointing to whatever object it was originally pointing to. No different than assigning it the value of another reference.
    It doesn't even mean the object on the heap is eligible for garbage collection, because there might be another reference pointing to it.
    Nazneen Ali likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 12-21-2012, 04:32 AM
  2. Initializing an array of class type variables.
    By xpl0rerchr in forum New To Java
    Replies: 5
    Last Post: 04-10-2012, 10:03 AM
  3. A reference to an object type?
    By LuxoJr in forum New To Java
    Replies: 13
    Last Post: 02-27-2012, 12:08 AM
  4. Replies: 9
    Last Post: 10-21-2011, 09:07 PM
  5. Replies: 4
    Last Post: 08-01-2011, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •