при использовании "text[*Number_of_lines].getLocalBounds()" происходит утечка памяти, в чем может быть причина?
Constructor:
ContextMenu::ContextMenu(Font &_font, int x, int y)
{
Background = new RectangleShape;
Highlighted_field = new RectangleShape;
CStandart = new Color(27, 27, 28);
GuidanceColor = new Color(45, 45, 48);
Number_of_lines = new short int(0);
text = (Text*) malloc (0 * sizeof (Text));
font = new Font(_font);
positionX = new int(x);
positionY = new int(y);
width = new float(0);
height = new float(1);
Visible = new bool(1);
Background->setPosition(x, y);
Background->setFillColor(*CStandart);
Highlighted_field->setFillColor(Color(45, 45, 48));
Highlighted_field->setPosition(x+1, y+1);
}
Destructor:
delete Background;
delete Highlighted_field;
delete CStandart;
delete GuidanceColor;
for (int i = 0; i < *Number_of_lines; i++)
{
text[i].~Text();
}
free(text);
//operator delete[] (text);
delete Number_of_lines;
delete font;
delete positionX;
delete positionY;
delete width;
delete height;
delete Visible;
Function with memory leak:
text = (Text*) realloc (text, (*Number_of_lines + 1) * sizeof (Text));
new (text + *Number_of_lines) Text;
text[*Number_of_lines].setString(PText);
text[*Number_of_lines].setFont(*font);
text[*Number_of_lines].setCharacterSize(11);
text[*Number_of_lines].setColor(Color(255, 255, 255));
text[*Number_of_lines].setPosition(*positionX + 4, *positionY + 15 * *Number_of_lines);
//*height = *height + 15;
//There is a memory leak!
FloatRect *Bounding_Rectangle = new FloatRect(text[*Number_of_lines].getLocalBounds());
cout << Bounding_Rectangle->width << ", " << Bounding_Rectangle->height <<endl;
//int temp_width = (Bounding_Rectangle->width + 8) * 1.02;
//if(*width < temp_width)
//{
// *width = temp_width;
//}
//Background->setSize(Vector2f(*width, *height + 1));//"+1"рамка
delete Bounding_Rectangle;
//Highlighted_field->setSize(Vector2f(*width - 2, 15));
//*Number_of_lines = *Number_of_lines + 1;
return *Number_of_lines;
Finally, a class call:
while(1)
{
ContextMenu *Menu_test = new ContextMenu(font, 50, 60);
Menu_test->addString(L"Test");
delete Menu_test;
}