Reputation: 338
I serialized an object of user defined linked list class, as every node of that list get a memory location in heap, while deserializing if the memory location is already occupied for a particular node , for example
if the memory of node 2 i.e. 200 is already occupied then how the node 1 knows about it and how the list deserialize? Or in java the memory allocation happens in some different way.
Upvotes: 2
Views: 1453
Reputation: 2340
JVM is responsible of object's management in memory. After any GC
is executed, objects allocated in memory can be moved, so the LinkedList
doesn't actually points a fixed adress but reference
Java has no pointers, only references to objects (safe references). A reference is similar to a pointer, because it points to a variable, an object, but you cannot view or edit the address memory of this reference (unlike C for example).
Upvotes: 2
Reputation: 4785
Generally speaking you would not have to do any thing about about heap manually in Java.
Serialization should not effect heap unless you have some references to serialized node.
Interms to linked list two nodes don't need to know where other node is in memory.
Hope this answers you question.
Upvotes: 1