• Post Reply Bookmark Topic Watch Topic
  • New Topic

How is classes,objects related in activation stack?  RSS feed

zurial zurial
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Corey thanxs for your flash application, it is really help a lot to understand what is actually going on in java program.
But, can anybody help me to answer some my questions regarding how classes, objects, modifiers related each others in activation stack and HEAP MEMORY??,
The most that make me think a lot is that what actually happens in Activation Record and HEAP MEMORY if one class extends another class or implements another class ??.
are each classes have theirs own activation stack and Heap Memory??.
What is happens in activation stack and HEAP MEMORY if we are casting one superclass to their subclasses?
How is modifiers control the activation stack and HEAP MEMORY??
I am sorry if I asked so many questions. The Corey's Flash application really make me excited to thinks more.

Thanks a lot.
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, let me try to explain.
There is only 1 activation stack per process. That's how the JVM knows what method is currently invoked, what method invoked it, and what the values are of local variables, etc.
Note that creating a new object doesn't really do anything to the activation stack. The only thing that would happed would be that a reference variable which references that object would appear on the stack.
For example:

Such a line would cause the placeholder for o (in the activation stack) to reference to new instance of the Object class. That object is created on the heap. Heap memory is just a pool of memory from which you can create objects, just like we did there. When an object is no longer used, the garbage collector returns that memory to the heap so that it can be used for other objects in the future.
Whether a class extends another class doesn't make much difference to the activation stack. The activation stack is really just a tool for keeping track of method invocations and local variables. (It's exceptionally useful to understand the activation stack when it comes to understanding recursion.)
However, what object is actually instantiated does make a difference to the heap. When you create a new object from the heap, the JVM must allocation a block of memory suitable for the actual object that is instantiated. Therefore, if we have the following situation:

If we were to instantiate a Child object (regardless of the fact that we might assign it to a Parent reference, like this:

In this case, the JVM must allocate a block of memory large enough to hold a Child object (which includes to ints, instead of one).
I hope that helps you get an idea of what the activation stack and heap are for and how they work.
I'm going to move this to the Java in General (Intermediate) forum as this won't be on the SCJP exam. Also, just as a note, the Flash application that Zurial is referring to can be found here. Please follow this thread within that forum.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!