0

i started learing java
reading thinking in java
i cam across this
java objects do not have same lifetime as primitives
an object retains in memory even after its scope until garbage collector detects and releases the memory

well whats the lifetime of primitives..??
their memory will be released after the scope..??

Edit/Delete Message

2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by JamesCherrill
1

It depends...
For primitives that are local variables declared inside methods or other blocks, and for method parameters, they are allocated on the stack and released as soon as they go out of scope.
For primitives that are declared as static members of a class, the lifetime is the same as the program's.
For primitives that are instance members of a class, their lifetime is the same as that of the instance in which they were created.

Edited by JamesCherrill

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.