This class ctor is leaking memory, I cant say what is going on. How I know? If I comment out the second ctor line, the leak goes away.
template< class T, int fixedSize >
class Resource_Cache{
private:
ID3D11Device * m_pDeviceRef; // the one that actually can create stuff
UINT m_iCurrentIndex; // next slot to be allocated, also the ID of the resources
//UINT m_nFreedSlots; // how many freed slot there are?
T* m_cache[fixedSize]; // the container per se
struct SlotInfo{
UINT nUseCount;
Resource_Descriptor<T> desc;
} m_slotsInfo[fixedSize];//use a hashtable<desc,index on m_cache>;
Resource_Cache(); //denied default ctor
public:
Resource_Cache( ID3D11Device * pDevice_p ): m_pDeviceRef(pDevice_p), m_iCurrentIndex(0){
memset(m_cache, NULL, fixedSize*sizeof(T*));
memset( m_slotsInfo, 0, fixedSize*sizeof(SlotInfo)); // zero slotsInfo memory(CAUSING LEAKS)
}
...
Might be simple stuff, but Im clueless..
- EDIT TO ANSWER - As PermanentGuest said: No. It doesn't give problems for elementary types. But, if your type T of Resource_Descriptor has some implementation which allocates memory in the constructor(e.g, string) by memset, you would be resetting any internal pointers of that class to NULL, thereby denying its destructor a chance to delete the memory. – PermanentGuest
std::string was the problem, solved.