Skip to content

Instantly share code, notes, and snippets.

@redotics
Created September 19, 2013 23:50
Show Gist options
  • Save redotics/6631457 to your computer and use it in GitHub Desktop.
Save redotics/6631457 to your computer and use it in GitHub Desktop.
This show that destructor is called on object at end of the block where they were called. With valgrind you could also see that the 42 allocated ints (42*4=168 bytes) are still here --> LEAK SUMMARY: definitely lost: 168 bytes in 1 blocks
#include <iostream>
#include <stdlib.h>
class Monstre {
public:
Monstre() { A = (int*)malloc(sizeof(int)*42); }
~Monstre() { std::cout << "iDestroy the new way of iPhoning." << std::endl; }
private:
int* A;
};
int main() {
int a = 5;
if (a > 3) {
Monstre Alf;
std::cout << "In the main, doing nothing" << std::endl;
}
std::cout << "Program over." << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment