aucd29 / cloning

Automatically exported from code.google.com/p/cloning
Other
0 stars 0 forks source link

Intensive use of a stack #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Cloning large object graphs might cause StackOverflowException as it did in my 
case. To overcome this problem I use jvm directive -Xss1028k. 

It should be possible to optimize algorithm by replacing recursion with 
iterative approach.

Original issue reported on code.google.com by Dzafar.S...@gmail.com on 8 Nov 2012 at 11:04

GoogleCodeExporter commented 9 years ago
Unfortunatelly I had to exclude deep clone library from project due to this 
stack issue. I used instead SerializationUtils.clone() from apache commons 
lang3 library. That worked good in my case because I could implement 
Serializable interface on each domain class. 

Original comment by Dzafar.S...@gmail.com on 14 Nov 2012 at 6:56

GoogleCodeExporter commented 9 years ago
the clone algorithm is by it's nature recursive. To do iterative approach will 
make the code very complicated and probably much slower.

StackOverflow problems arise with objects that look like a list of nodes and 
not a graph of objects. I.e. an object "graph" that looks like

head->tail>tail2>tail3>tail4

will require 5 recursive calls where as a graph of

  head
  |   \      \
tail1  tail2  tail3

will require just 2.

If you could find which of your objects look like a linked list, then you could 
create a FastCloner like the FastClonerLinkedList and the problem will be solved

Original comment by kostas.k...@googlemail.com on 7 Dec 2012 at 8:34

GoogleCodeExporter commented 9 years ago

Original comment by kostas.k...@googlemail.com on 7 Dec 2012 at 8:34