Stack overflow - 32 deep class hierarchy

by thesquib » Sat, 27 Dec 2008 07:03:29 GMT


Sponsored Links
 I have come across an interesting problem. If I have a class hierarchy
that is 32 deep and attempt to instantiate the 32nd one, the VM breaks
with a stack overflow. I take it this is expected - 32 seems like a
'magic' number. Debugging shows that the VM fails to load the class,
tries to throw and exception and goes into infinite recursion. Can
anyone shed a bit of light on the situation?

Example class hierarchy:
class T1 {}
class T2 extends T1 {}
class T3 extends T2 {}
class T4 extends T3 {}
class T5 extends T4 {}
class T6 extends T5 {}
class T7 extends T6 {}
class T8 extends T7 {}
class T9 extends T8 {}
class T10 extends T9 {}
class T11 extends T10 {}
class T12 extends T11 {}
class T13 extends T12 {}
class T14 extends T13 {}
class T15 extends T14 {}
class T16 extends T15 {}
class T17 extends T16 {}
class T18 extends T17 {}
class T19 extends T17 {}
class T20 extends T19 {}
class T21 extends T20 {}
class T22 extends T21 {}
class T23 extends T22 {}
class T24 extends T23 {}
class T25 extends T24 {}
class T26 extends T25 {}
class T27 extends T26 {}
class T28 extends T27 {}
class T29 extends T28 {}
class T30 extends T29 {}
class T31 extends T30 {}
class T32 extends T31 {}
class T33 extends T32 {}


-Sam

--~--~---------~--~----~------------~-------~--~----~



Stack overflow - 32 deep class hierarchy

by thesquib » Tue, 30 Dec 2008 03:55:59 GMT


 I posted this at the worst time of the year :)
I just wanted to add that I am interested in finding a way around
this, or just to find out if it is a limitation which will not go
away.




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Stack overflow - 32 deep class hierarchy

by Mark Murphy » Tue, 30 Dec 2008 04:04:07 GMT


 


I'd focus instead on getting rid of 20+ classes in the hierarchy.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



Stack overflow - 32 deep class hierarchy

by thesquib » Tue, 30 Dec 2008 05:49:13 GMT


 Thanks for your reply Mark. I realise that the best solution is to
collapse the hierarchy, however I am still interested to know the
cause.





--~--~---------~--~----~------------~-------~--~----~