Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: scope of variable understanding problem?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default scope of variable understanding problem?

    Hi,

    i know scope of a variable declare in a function remain with in the function. but i want to know Is the objects that create in a function remain in the memory after the function finish its execution.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: scope of variable understanding problem?

    Yes, for awhile. The only way memory is cleared up is by a process called garbage collection. When a java program is running, the virtual machine will occasionally automatically run its garbage collection process to get rid of anything in memory which will no longer be used. To my understanding, java really only runs it when it starts to get low on memory.

    Based on your question, I suspect you are attempting to see if you can find that object in memory after the function has finished. There is probably some way of doing it, but it is not something you should do; mainly because you don't know if the object will still be in memory when you look. The garbage collection might have ran and gotten rid of it in the mean time. There isn't really a nice way of checking.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Help understanding the result of a type int variable
    By Abadude in forum Object Oriented Programming
    Replies: 3
    Last Post: December 11th, 2012, 09:38 AM
  2. [SOLVED] Out of scope problem
    By lf2killer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2012, 04:28 AM
  3. scope of a class created as local variable
    By Samaras in forum Java Theory & Questions
    Replies: 6
    Last Post: August 25th, 2012, 06:01 PM
  4. Scope problem
    By TP-Oreilly in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 9th, 2011, 08:41 AM
  5. Variable Scope
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 7
    Last Post: October 5th, 2011, 04:08 PM

Tags for this Thread