I have a class here that is defined like this:
struct USERFPOINT
{
POINTFLOAT UserPoint;
POINTFLOAT LeftHandle;
POINTFLOAT RightHandle;
bool isBezier;
};
struct SHAPEOUTLINE {
GLuint OutlineVBO;
int OutlineSize;
int OutlineWidth;
ARGBCOLORF OutlineColor;
};
struct SHAPECONTOUR{
std::vector<USERFPOINT> UserPoints;
std::vector<std::vector<GLdouble>> DrawingPoints;
SHAPEOUTLINE Outline;
};
struct SHAPEGRADIENT{
GLuint TextureId;
bool IsParent;
bool active;
int type;
std::vector<ARGBCOLORF> colors;
};
struct SHAPEDIMENSIONS {
POINTFLOAT Dimensions;
POINTFLOAT minima;
POINTFLOAT maxima;
};
class OGLSHAPE
{
private:
int WindingRule;
GLuint TextureCoordsVBOInt;
GLuint ObjectVBOInt;
UINT ObjectVBOCount;
UINT TextureCoordsVBOCount;
SHAPEGRADIENT Gradient;
SHAPEDIMENSIONS Dimensions;
void SetCubicBezier(USERFPOINT &a,USERFPOINT &b, int ¤tcontour);
void GenerateLinePoly(const std::vector<std::vector<GLdouble> > &input, int width);
public:
std::string Name;
ARGBCOLORF MainShapeColor;
std::vector<SHAPECONTOUR> Contour;
OGLSHAPE(void);
void UpdateShape();
void SetMainColor(float r, float g, float b, float a);
void SetOutlineColor( float r, float g, float b, float a,int contour );
void SetWindingRule(int rule);
void Render();
void Init();
void DeInit();
~OGLSHAPE(void);
};
Here is what I did as a test. I created a global std::vector<OGLSHAPE>
test .
In the function I was using, I created
OGLSHAPE t.
I then pushed 50,000 copies of t into test.
I then instantly cleared test and used the swap trick to really deallocate it.
I noticed that all the memory was properly freed as I would expect.
I then did the same thing but before pushing t into test, I pushed a SHAPECONTOUR (which I had just created without modifying or adding anything into the contour) before pushing t into test.
This time after clearing test, 3 more megabytes had been allocated. I did it again allocating twice as many and now 6MB we remaining. The memory usage of the program peaked at 150MB and it went down to 12MB, but it should be at 8.5MB. Therefore, this must be classified as a memory leak, although I do not see how. There is nothing that I see that could do that. SHAPECONTOUR is merely a structure of vectors with a nested structure of vectors.
Why would this cause a leak, and how could I fix it?
Thanks