| | |
Help me find my memory leak!
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
I'm not too sure why I'm getting memory leaks...hopefully someone here is wiser than me, and can help me find it
.
this is the class where it's occurring. If anyone needs the other classes/files just ask. Thanks!
. C++ Syntax (Toggle Plain Text)
#include "Canvas.h" CDrawer CCanvas::gCanvas(RGB(0,0,0), 1); int const GREEN(20000),BLUE(50), RED(200), THICK(3); CCanvas::CCanvas(void): _iSize(0), _cptPoints(0) { } CCanvas::CCanvas(CCanvas const & tmpCanvas): _iSize(tmpCanvas._iSize) { if (_iSize > 0) { _cptPoints = new CPt [_iSize]; for (int i(0); i < _iSize; ++i) { _cptPoints[i]._iX = tmpCanvas._cptPoints[i]._iX; _cptPoints[i]._iY = tmpCanvas._cptPoints[i]._iY; _cptPoints[i]._COLOR = GREEN; } } } CCanvas CCanvas::operator =(const CCanvas & RHS) { if (RHS._iSize > 0) { _iSize = RHS._iSize; _cptPoints = new CPt [RHS._iSize]; for (int i(0); i < _iSize; i++) { _cptPoints[i]._iX = RHS._cptPoints[i]._iX; _cptPoints[i]._iY = RHS._cptPoints[i]._iY; _cptPoints[i]._COLOR = RED; } } return *this; } CCanvas & CCanvas::Show(void) { if (_iSize > 1) { gCanvas.Clear(); for (int i(0); i < _iSize - 1; ++i) { for (int ii(i + 1); ii < _iSize; ++ii) if (i != ii) ShowPts(gCanvas, _cptPoints[i], _cptPoints[ii]); } gCanvas.Render(); } return *this; } CCanvas::~CCanvas(void) { Clean(); } CCanvas & CCanvas::AddLines(int iX, int iY, COLORREF tmpCol) { CPt * Tmp = new CPt [_iSize + 1]; for (int i(0); i < _iSize; ++i) { Tmp[i]._iX = _cptPoints[i]._iX; Tmp[i]._iY = _cptPoints[i]._iY; Tmp[i]._COLOR = _cptPoints[i]._COLOR; } Clean(); _cptPoints = new CPt [++_iSize]; _cptPoints = Tmp; Tmp = 0; _cptPoints[_iSize-1]._iX = iX; _cptPoints[_iSize-1]._iY = iY; _cptPoints[_iSize-1]._COLOR = tmpCol; Show(); return *this; } void CCanvas::Clean(void) { delete [] _cptPoints; _cptPoints = 0; }
this is the class where it's occurring. If anyone needs the other classes/files just ask. Thanks!
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
These lines here
You allocate space for _cptPoints, and then you assign it to Tmp, which means you've now lost the memory pointer assigned by new CPt [++_iSize]; .. therefore not sure how you can delete it. That may be causing one of your leaks.
_cptPoints = new CPt [++_iSize]; _cptPoints = Tmp;
You allocate space for _cptPoints, and then you assign it to Tmp, which means you've now lost the memory pointer assigned by new CPt [++_iSize]; .. therefore not sure how you can delete it. That may be causing one of your leaks.
•
•
Join Date: Apr 2008
Posts: 129
Reputation:
Solved Threads: 22
remove this line
cpp Syntax (Toggle Plain Text)
_cptPoints = new CPt [++_iSize];
![]() |
Similar Threads
- Memory leak in game (C++)
- can't find my memory leak (C++)
- Program crashing, need good debugger (C++)
- memory leak problem... (C)
- Memory Leak? (C)
- OOp memory leak error (C++)
- “Windows Virtual Memory Size Too Low� in XP (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Any help with C++ payroll! -noob
- Next Thread: Search an array of objects.
Views: 448 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





