gestion de la mémoire - Quoi et où sont la pile et le saut

Mots clés : memory-managementstacklanguage-agnosticdynamic-memory-allocationheap-memorymemory-management

meilleur 2 Réponses gestion de la mémoire - Quoi et où sont la pile et le saut

vote vote

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; 
vote vote

86

public void Method1() {     int i = 4;     int y = 2;     class1 cls1 = new class1(); } 

Questions similaires