|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Jun 2007
Messaggi: 9
|
Memory Leak letale (C++)
Ciao a tutti, ho un problema su cui sto sbattendo la testa da ormai troppe ore senza scorgere uno spiraglio di soluzione: non riesco a liberare la memoria nello heap. La classe è la seguente: nel metodo InsertTag alloco un array di _TCHAR da inserire nella map "tags". Quando nel distruttore (codice commentato) vado a far riferimento a quell'array per liberarlo l'esecuzione termina dicendo che il riferimento è fuori dallo heap.
Spero che qualcuno mi illumini. Grazie Codice:
typedef map<_TCHAR*,int,compare> myMap; class Es2Window { HWND hWnd; HWND hButton; HWND hEdit; Pen *mypen; myMap tags; public: Es2Window(HWND hWnd) { this->hWnd = hWnd; mypen = new Pen(Color::Black,3.0); RECT r; GetClientRect(hWnd, &r); hButton = CreateWindowW(L"BUTTON", L"Ok", WS_CHILD|WS_VISIBLE, r.right-100, r.bottom-25, 100, 25, hWnd, (HMENU)IDC_BUTTON, hInst, NULL); hEdit = CreateWindowW(L"EDIT", NULL, WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, 0, r.bottom-25, r.right-100, 25, hWnd, (HMENU)IDC_EDIT, hInst, NULL); } ~Es2Window() { delete mypen; //myMap::iterator mapIter = tags.begin(); //myMap::iterator mapEnd = tags.end(); //for (; mapIter != mapEnd; mapIter++) { // delete[] mapIter->first; //} } Pen * getPen() {return mypen;} void Refresh() { RECT r; GetClientRect(hWnd, &r); MoveWindow(hButton, r.right-100, r.bottom-25, 100, 25, TRUE); MoveWindow(hEdit, 0, r.bottom-25, r.right-100, 25, TRUE); } void InsertTag(_TCHAR *newtag) { pair<myMap::iterator, bool> ret; _TCHAR *entry = new _TCHAR[_tcslen(newtag)]; _tcscpy(entry, newtag); ret = tags.insert(pair<_TCHAR*,int>(entry, STARTSIZE)); if (ret.second == false) { ret.first->second++; } } myMap& getTags() {return tags;} }; |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:26.