Hello,
I've come across one rather strange kind of memory leak. I always thought memory leaks where caused if you forget to delete a resource you allocated, or loose a pointer to it, but this one... well, look:
void Text::Draw(render::Stage& stage, const math::Rect& rect, LPCWSTR lpText, DWORD dFlags, float f)
{
math::Rect r(rect);
r.width += rect.x;
r.height += rect.y;
/* Leak: */
delete m_pCall;
m_pCall = new render::DrawFont(m_pActiveFont->GetAclFont().m_lpFont, lpText, r.GetWinRect(),
dFlags, m_color.GetD3DColor());
/* End Leak */
m_pInstance->SetCall(*m_pCall);
stage.SubmitInstance(*m_pInstance);
}
So, those two lines cause the leak. If I draw some text using this (unoptimized, hackaround-like) font rendering method for my renderer, memory used by the application will rise continously in small amounts noticable in the task manager. Here is how my DrawFont-method is declared:
class DrawFont : public DrawCall
{
public:
DrawFont(const LPD3DXFONT font, const std::wstring& stText, const RECT& rect, DWORD flags, D3DCOLOR color): stText(stText), font(font), rect(rect),
flags(flags), color(color) { type = Font; }
void Execute(const DX9Device& device) const
{
RECT r(rect);
font->DrawTextW(nullptr, stText.c_str(), stText.size(), &r, flags, color);
}
private:
RECT rect;
DWORD flags;
std::wstring stText;
D3DCOLOR color;
const LPD3DXFONT font;
};
Now uhm... I don't really see any reason why this could leak memory. I'm deleting the draw call I allocated before, I'm not newing anything in between those two actions concerning the DrawFont-class, and the general render interface doesn't show this leaking behaviour, its only the text-class. Also it has nothing to do with calling the "Execute"-function, even if I comment out the part in my render queue where this call is processed, it still leaks. As soon as I comment out that two lines, no such rise in memory. Am I really that stupid, or is there some good reason why memory usage could rise by those simple actions and/or something I missed out?