Results 1 to 11 of 11
  1. #1
    mailboxo71 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Newbie needs help clearing memory objects

    What is the proper way to clean up memory of the following objects?
    NSString *style = @"Red";

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Whenever something goes out of scope it is eligible for garbage collection. Therefore declare your variables in the smallest possible scope.

  3. #3
    user0 is offline Senior Member
    Join Date
    Dec 2010
    Posts
    100
    Rep Power
    0

    Default

    Hi is this a Java question?
    --user0--

  4. #4
    mailboxo71 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    Yes, its a Java ques. I need to know if I can manually in program to free up objects variables.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    No, java does garbage collection.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Don't bother. Java has a Garbage Collector which manages it for you. It is quite possible that any attempt to manipulate it by you will simply make matters worse.

  7. #7
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by mailboxo71 View Post
    Yes, its a Java ques. I need to know if I can manually in program to free up objects variables.
    You can request the JVM to run the garbage collector by calling the System.gc() or Runtime gc() methods. But there is NO guarantee whatsoever that JVM will acknowledge your request.

    JVM usually runs the garbage collector automatically when it feels that the memory is low.

    So it's better to leave this job for JVM.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by mailboxo71 View Post
    Yes, its a Java ques. I need to know if I can manually in program to free up objects variables.
    I guess it's Objective C. Clearing a string in C is easy: simply set all of it's bytes (i.e. char or w_char) to \0.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    Quote Originally Posted by mailboxo71 View Post
    Yes, its a Java ques.
    Java Code:
    NSString *style = @"Red";
    This is Java?
    When did they change the syntax?
    :confused:

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    Java Code:
    NSString *style = @"Red";
    This is Java?
    When did they change the syntax?
    :confused:
    Nope, it's Objective C (NS stands for Next Step). It's a nice little language and Java 'borrowed' a lot from it ;-) (the leading '@' defines a Unicode String if I remember well).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    Which doesn't explain why the OP decided it was Java.
    (And I was ignoring your earlier post for comedy value)
    ;)

Similar Threads

  1. Dialog box clearing graphics
    By theborland in forum Java Applets
    Replies: 1
    Last Post: 12-03-2010, 08:27 PM
  2. emptying/clearing an array
    By i8java in forum New To Java
    Replies: 2
    Last Post: 08-09-2010, 02:39 PM
  3. Help Clearing BufferedImage
    By ketann in forum Java 2D
    Replies: 19
    Last Post: 03-29-2010, 08:45 PM
  4. ow many objects I have open in the memory
    By itaipee in forum Advanced Java
    Replies: 1
    Last Post: 11-23-2009, 10:16 AM
  5. MouseListener - clearing a textField when clicked on?!
    By sailor_girl in forum AWT / Swing
    Replies: 4
    Last Post: 03-01-2009, 06:01 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
  •