1. Home >
  2. Apps >
  3. Groups >

A query related to Java objects

Question asked by Whats In Name in #Java on May 18, 2013
Whats In Name
Whats In Name · May 18, 2013
Rank B3 - LEADER
So What I understood is that-

Classname object=new Classname();

Here an object will be created in heap and the reference to it will be stored in stack.After we close the program the reference is lost from stack but object still resides in heap(although the memory now is free for reallocation).

Is it correct?Because If it is, then only I will ask my further query.😁 Posted in: #Java
Nayan Goenka
Nayan Goenka · May 18, 2013
Rank B1 - LEADER
Yes its correct, Stack is for temporary data members, heap is for permanent ones. Whats the query. Also these links might be useful to you. do read them. they might clear your doubts.

https://www-numi.fnal.gov/computing/...ocs/Companion/first_steps/stack_and_heap.html
https://www-numi.fnal.gov/computing/minossoft/releases/R2.2/WebDocs/Companion/glossary/stack.html
https://www-numi.fnal.gov/computing/minossoft/releases/R2.2/WebDocs/Companion/glossary/heap.html
Whats In Name
Whats In Name · May 18, 2013
Rank B3 - LEADER
So If we somehow acknowledge the value of the reference variable which actually has a address then after closing the program can we point to the same address again(manually)?
Nayan Goenka
Nayan Goenka · May 18, 2013
Rank B1 - LEADER
Whenever you make a program you allocate some memory to it for its functioning. It does not mean that you will fool around the entire hard disk with hex dumps to certain locations and try to access them. the point is, stacks are references to data objects in heaps, but in the memory location of the heap, the data is stored along with pointer to its referrer. your program knows where to look for it when its compiled but if you provide hex dumps in your program it MAY show error and treat as garbage value. You may use it in one instance but what about when the some other program or the same one as your previous one traverses the memory location? the whole new program will get corrupt due to unsanctioned usage of memory location and overlapping of pointers. Also it is not recommended to do so as the program will not respond as it is intended to. This type of coding is done when working on Emulators or making your own BootShell where there is an entire concept related to memory programming. It is not compatible or either recommended for your Java Apps or functions.
Whats In Name
Whats In Name · May 18, 2013
Rank B3 - LEADER
It was very informative.Thanks!

.the data is stored along with pointer to its referrer. your program knows where to look for it when its compiled but if you provide hex dumps in your program it MAY show error and treat as garbage value.
Doesn't that hex dump equals the reference which is stored along with the data?

Sorry,If it sounds like an annoying query.😕
Nayan Goenka
Nayan Goenka · May 18, 2013
Rank B1 - LEADER
It does but in an overall view that is not the only program running on your computer, there are hundreds more, also include the compiler compiling for you, you can never predict. The case maybe different if you get into Debuggers and find out which program is running on which memory, which traversing agents are active and which exact memory space is isolated (which is none 😛), you cannot manage to give a direct call to data on a specific memory address.
Whats In Name
Whats In Name · May 18, 2013
Rank B3 - LEADER
Thanks a lot! I am glad I got the answer😀
Nayan Goenka
Nayan Goenka · May 18, 2013
Rank B1 - LEADER
Thanks, happy to help 😁
rahul69
rahul69 · May 21, 2013
Rank B2 - LEADER
Nayan Goenka
Whenever you make a program you allocate some memory to it for its functioning. It does not mean that you will fool around the entire hard disk with hex dumps to certain locations and try to access them. the point is, stacks are references to data objects in heaps, but in the memory location of the heap, the data is stored along with pointer to its referrer. your program knows where to look for it when its compiled but if you provide hex dumps in your program it MAY show error and treat as garbage value. You may use it in one instance but what about when the some other program or the same one as your previous one traverses the memory location? the whole new program will get corrupt due to unsanctioned usage of memory location and overlapping of pointers. Also it is not recommended to do so as the program will not respond as it is intended to. This type of coding is done when working on Emulators or making your own BootShell where there is an entire concept related to memory programming. It is not compatible or either recommended for your Java Apps or functions.
Interesting discussion!😀 Nayan Goenka correct me if I am wrong but I think by the time that memory of object will be accessed by using hex dumps, it would had already been cleared by Garbage Collector, so there would not be anything useful there to be accessed.
Nayan Goenka
Nayan Goenka · May 21, 2013
Rank B1 - LEADER
Garbage Collector is nothing else but another program, instead of using the specific name, i generalized it by other program 😀.
Whats In Name
Whats In Name · May 21, 2013
Rank B3 - LEADER
Computer memory!Interesting it is.😀
Nayan Goenka
Nayan Goenka · May 21, 2013
Rank B1 - LEADER
Sure it seems interesting, Just try and use a single debugger or memory mapper, you will understand. It was a nightmare for me when i had to use that, trust me, it tests all your patience. 😛

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up