Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I release CStringArray?

Status
Not open for further replies.

Aunthas

Programmer
Oct 8, 2002
7
0
0
TH
I've declared CStringArray m_saRule.
When I want to release it, I use the following code.

int nNumRule = m_saRule.GetSize();
for(int pos=0; pos<nNumRule; pos++)
delete m_saRule[pos];
m_saRule.RemoveAll();

But it has an error in runtime.
What's wrong? How can I release it?
Thank you very much.
 
I'm sure that this:
m_saRule.RemoveAll();
Cleans up the memory for you.
Here's a trick to see for sure:

int nNumRule = m_saRule.GetSize();
for(int pos=0; pos<nNumRule; pos++){
delete m_saRule[pos];
m_saRule[pos] = NULL;
}
m_saRule.RemoveAll();

If the runtime error dissapears, it means that RemoveAll() will clean up for you and hence your cleanup code is unnecessary. If the problem persists, well, I'm not sure, perhaps you could write your own string array class (trivial).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top