Mots clés : memory-managementstacklanguage-agnosticdynamic-memory-allocationheap-memorymemory-management
97
int foo() { char *pBuffer; //<--nothing allocated yet (excluding the pointer itself, which is allocated here on the stack). bool b = true; // Allocated on the stack. if(b) { //Create 500 bytes on the stack char buffer[500]; //Create 500 bytes on the heap pBuffer = new char[500]; }//<-- buffer is deallocated here, pBuffer is not }//<--- oops there's a memory leak, I should have called delete[] pBuffer;
86
public void Method1() { int i = 4; int y = 2; class1 cls1 = new class1(); }