Results 1 to 6 of 6
  1. #1
    SaYuNaRa is offline Member
    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    Question what happen if an object set to null

    if i set an object to null, is it make an object to an empty object?
    and the memory use by that object is remove or not?

    example ?
    ImageIcon icon = new ImageIcon(file) //example use 8 byte
    Image img = icon.getImage(); //example use 8 byte

    if i set to null:

    icon = null; // is the memory use by icon remove or not
    img = null; // is the memory use by img remove or not

    is that memory use by icon and img remove or not? if not remove how to remove the icon and img memory becouse i want use the same object to set another refrence.

    I do that becouse it make my app out of memory

  2. #2
    Join Date
    Apr 2008
    Location
    Fort Wayne, Indiana
    Posts
    62
    Rep Power
    0

    Default

    If you use the System.gc() after you set the object to null it should free up the memory. It may need to be called multiple times to make sure all unused memory is freed up. Check out the following website for more information.

    [JavaSpecialists 029] - Determining Memory Usage in Java

  3. #3
    SaYuNaRa is offline Member
    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    Default

    thx for your help..

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I wonder why you like to set it to null? What are you planning for?

    regards,
    sukatoa

  5. #5
    SaYuNaRa is offline Member
    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    Default

    i want set to null, becouse i want use the same object to refer to other. like img object:

    this i want:
    ico = new ImageIcon("c:/image/pic1.pmg")
    img = ico.getimage();


    this i refre to other:
    ico = null;
    img = null;
    so i can set new refer
    ico = new ImageIcon("c:/image/pic2.pmg")
    img = ico.getimage();

    if i not set it to null before i use its again my app will out of memory. this right or not?
    i do what Chris.Brown said, and it work, my app not of memory.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 03:12 AM
  2. Img.getWidth(null); gives -1 why?
    By willemjav in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 03:06 PM
  3. What is NULL
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 05:55 PM
  4. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM
  5. To happen of ActionErrors to ActionMessage
    By Eric in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 08:09 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
  •