java - Heapoverflow instead of Stackoverflow in infinite loop -
java - Heapoverflow instead of Stackoverflow in infinite loop -
in java when method calls , results in infinite loop stackoverflow error thrown. while objects initialized in heap memory shouldn't heap memory overflow error thrown since object involved phone call method.? there such thing heapoverflow error?!
you're on right track. can run out of heap memory it's not called heapoverflow. it's called outofmemoryerror. although heapoverflow sounds catchy it's not called because heap has free , allocated areas scattered through out. stack on other hand has 2 areas, free , allocated. allocated area grows free area create more allocations on stack. hence overflow stack. more on stack vs heap here.
here illustration of running out of heap memory:
public class runoutofmemory { public static void main(string[] args){ system.out.println("haven't tried allocate lots of heap memory."); int[][] matrix = new int[100000][100000000]; system.out.println("a miracle occured."); } }
spoiler alert: need 4 terabytes of memory miracle occur
java object stack heap stack-overflow
Comments
Post a Comment