user1056075
user1056075

Reputation:

JVM halts without completing method will the local variable still remains in stack?

Local variables gets placed in stack when method is called and when JVM halts without completing the method, will the local variable still remain on the stack?

Example:

void Method() {
    int a=2;
    System.exit(0);
    Foo f=new Foo();
}

Upvotes: 2

Views: 88

Answers (4)

user207421
user207421

Reputation: 310909

There is no stack after the process exits, so there are certainly no local variables left on it, or anything else either.

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 284826

The Java-level stack will be gone, and the OS will free the memory. However, nothing is going to actually zero it out so the stack variables will remain in that sense.

Upvotes: 0

Udo Held
Udo Held

Reputation: 12538

When you restart the vm you will have fresh values and a fresh stack. Anything after a System.exit(0) won't be called.

Upvotes: 0

DejanLekic
DejanLekic

Reputation: 19797

No. After the System.exit(0) the system will clean-up the mess.

Upvotes: 2

Related Questions