I have question regarding memory leaks. I was using some test code to create anonymous object arrays of a certain size and return the addresses to a pointer. I put the code in a loop and was curious if I could run my computer out of memory.
I was not sure what I observed in my activity monitor; it locked up. The program eventually crashed with this error:Code:long double *mem = new long double(1073741824); long double *poop; while (1) { poop = new long double[1073741824]; std::cout << "Memory Allocated: " << (*mem += 1073741824) << std::endl; }
Memory Allocated: 8.79395e+12
Memory Allocated: 8.79502e+12
Memory Allocated: 8.79609e+12
C++Primer(2721) malloc: *** mmap(size=17179869184) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
What did I manage to do and why did I manage to not lock up my computer in the process with that much memory leak? Am I clueless? yes!
PS> Can someone please explain why when I delete a dynamically allocated memory location it can still be referenced by the pointer?



LinkBack URL
About LinkBacks



