?
Solved

Object Reference

Posted on 2003-02-18
4
Medium Priority
?
164 Views
Last Modified: 2010-03-31
The problem I met is with Java I try to use serialization or clone ,whatever, to backup an object(name it "object1"), so later if any dirty data occurs , I could take the stored object back and rollback.
But unfortunately the object I took back(using deserialization) is actually generating a new object (name it "object2"). The reference of object1 is not equal to object2 which means they are different objects in the memory space. But I hope I can restore the backup object to the original memory space. Is there any good method to do so? Or is it possible? Thx
0
Comment
Question by:magich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:allahabad
ID: 7979572
FileInputStream istream = new FileInputStream("file.tmp");
ObjectInputStream p = new ObjectInputStream(istream);

obj1 = (ObjectType1)p.readObject();
obj2 = (ObjectType2)p.readObject();

istream.close();

Assume reference name in VM for objects are obj1, obj2 . Now obj1,obj2 will point to object retreived from the persistance store.
0
 
LVL 3

Accepted Solution

by:
msterjev earned 225 total points
ID: 7979879
First at all deserialization is reading a class information and instance object information. After reading that information VM creates new object instance and initializes it with the serialized object information. This a new object with its own reference. There is no way to restore the object in its original memory address, because that is in the contrary with the Java concept. Java is not dealing with pointers and there is a constantlly running garbage collector, so the valid reference in one moment can an invalid reference in the future.
0
 

Author Comment

by:magich
ID: 7982176
hi msteriev:
So based on you comment. before serialization, if object1 is referred by some other objects. afte serialization and deserialization such refering relation will lose. Since serialization can keep the referance from object1 to other objects but not the referance from other objects to object1. Is it? thx
0
 
LVL 3

Expert Comment

by:msterjev
ID: 8298818
Yes!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question