ATL/COM: How to create/maintain an array of CComObjects?
Posted on 2001-06-25
I am changing the implementation of our own grid control form using an array of structs for all cells to using an array of Com objects. I have a working solution, but I don't seem to be able to delete the objects I created, which shows in practice as a huge resource/memory leak.
I would like them to be in an array, but if there's a better/easier solution I will certainly look into it (but not MFC!). Furthermore, in the current implementation I create every object anew, but I guess copying/cloning to be much faster. It's probably easy to implement, I just don't know how.
This is how my declaration looks:
This is how it is updated when the dimensions of the grid change:
m_lpCellsProp = new CComObject<CFastGridCell>[m_cols * m_rows + 1];
for(int irow=1; irow<=m_rows; irow++)
for(int icol=1; icol<=m_cols; icol++)
int id = getCellID(irow, icol);
m_lpCellsProp[id] = new CComObject<CFastGridCell>();
//do some things on the object, like:
I have no idea how the delete statement should like. I didn't get any to work. Maybe I do it all wrong. I never worked with arrays of some template type, let alone arrays of CComObject types. If someone knows how to do the same with multidimensional arrays, it'll be even more appreciated.
Btw, the above implementation works well in debug builds, but gives an access denied error after the first tens of object's constructs/destructs.
Btw2, the idea is to provide some kind of aggregation, but again, I never did that, except for simple objects like IFont and such.
Thanks in advance for any ideas,