I am trying to Serialize an array that contains about 150,000 objects. The problem is that each object in the array has a references to some other objects that are also in the array so I end up with a massive object tree where all the objects are referencing one another.
Unsuprisingly I get a stack overflow when I try to Serialize this array as serialization recursivly traverses the object graph. (i can not increase the stack size with this particular problem)
I tried iterating over each element of the array and calling writeObject on it but it made no difference I still got a stack overflow.
So I implemented the write and read object methods in the class of the objects that are held in the array but I dont think I have done it correctly because when I read in the file again into a new array the number of elements in the array and all the variables inside each of the objects exist but they are all Null or 0. So either it is not writing it properly or not reading it. I think it might be the latter as I dont think in.readObject does anything as far as I can tell.
I have also tried writing and reading each variable in the object but it comes up with stackOverFlowError when I try to write to the file.
Any body had these problems when doing Serialization on large numbers of selfreferencing objects? Can somebody point me in the right direction?
In order to reproduce the problem, please post all of your code. While it's possible that the stack overflow is caused by the amount of data, could it also be that you have a reentrancy problem with your objects pointing at one another? That is, could you recreate the problem with a very small set of data? Also please post the full error.
Joined: Dec 23, 2008
This post is over a year and a half old, best to let old threads die. I think I got round the problem by doing my own serialization instead of the built in Java serialization.