Results 1 to 6 of 6
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default String Immutability and Memory

    As string literals are not applicable for garbage collector (String Literal Pool), so if I have a string literal like s = "ousdfkjliejlskjfodsjflk" and I use only few characters from this string, then the whole string (s) will remain in the memory till the end of programme that can cause memory leakage I think (correct me if I am wrong). Is there any method to overcome this problem ?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: String Immutability and Memory

    Its not a problem.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: String Immutability and Memory

    what is this then ?

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: String Immutability and Memory

    Working as designed.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: String Immutability and Memory

    Quote Originally Posted by allaudin View Post
    As string literals are not applicable for garbage collector (String Literal Pool), so if I have a string literal like s = "ousdfkjliejlskjfodsjflk" and I use only few characters from this string, then the whole string (s) will remain in the memory till the end of programme that can cause memory leakage I think (correct me if I am wrong). Is there any method to overcome this problem ?
    Nothing leaks from the String pool; aamof there is no memory leaking at all in Java (if the implementation isn't broken).

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 08-20-2012, 06:38 PM
  2. Replies: 1
    Last Post: 07-18-2011, 04:24 PM
  3. String Intern & Java memory
    By GKUIUC in forum Advanced Java
    Replies: 5
    Last Post: 10-09-2010, 02:16 PM
  4. Immutability compromised if 'final' is omitted?
    By JUser in forum Advanced Java
    Replies: 1
    Last Post: 09-28-2010, 09:02 AM
  5. Replies: 2
    Last Post: 08-21-2008, 07:33 PM

Posting Permissions

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