A query related to Java objects

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.😁

Replies

  • Nayan Goenka
    Nayan Goenka
    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.

    #-Link-Snipped-#
    #-Link-Snipped-#
    #-Link-Snipped-#
    ​
  • Whats In Name
    Whats In Name
    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
    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
    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
    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
    Thanks a lot! I am glad I got the answerπŸ˜€
  • Nayan Goenka
    Nayan Goenka
    Thanks, happy to help 😁
  • rahul69
    rahul69
    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!πŸ˜€ #-Link-Snipped-# 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
    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
    Computer memory!Interesting it is.πŸ˜€
  • Nayan Goenka
    Nayan Goenka
    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 are reading an archived discussion.

Related Posts

In Indian smartphone market we have Nokia Lumia 520 (~10-11K), 620 (14-15K), 720 (18-19K), 820 (23-24 K) and 920 (35-38 K). Feature wise, except Lumia 520 all have front and...
I have know some details. I need an more details about inverter. what are the procedure to do inverter business and how investments and how is markets for inverter. please...
Google IO's keynote revealed all the amazing improvements and modifications that Google Now had undergone. With the mind blowing responses to everyday questions, now there are speculations rising on how...
At Integrated Ideas, we work constantly at different productivity and entertainment products. Research is of various kind. Recently we decided to take a ride of mathematics, especially complex maths with...
Hey, I was wondering if crazy engineers are interested in launching an Android/Windows-phone and desktop/IOS app for our forum. If yes, post in ideas about it and whos willing to...