Dynamic 2d array in c++ and memory leaks -


i wrote code. runs ok, when check under valgrind catches 2 problems. since can not interpret valgrind's messages appreciate if explain me more , tell me problem!!!

here code:

#include <iostream>  #define width  70000  #define height 10000  using namespace std;  int main(void) {     int** pint;       pint = new int*[height];     for(int = 0; < height; i++)         pint[i] = new int[width];      for(int = 0; < height; i++){         delete[] pint[i];         pint[i] = null;     }      delete[] pint;     pint = null;       return 1; } 

okay, there couple of valgrind warnings 3.4 first important.

new/new[] failed , should throw exception, valgrind cannot throw exceptions , aborting instead. sorry.

new throws exception when out of memory (unless use nothrow version of new). unfortunately, valgrind cannot handle , gives before code completes. because valgrind aborts, code free memory never executed shows memory leaks.

that said, not handling case new throws program die due unhandled exception if run out of memory. need wrap code try/except block.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -