lapucca
asked on
Why do I get uninilize memory when deleting and cleaning up my vector queue in my desctructor?
vector <CUserContextData> userDataObjects;
vector <wstring> primaryGroups;
//Erase all items in the group vector queueu and the user data object queue
if(!primaryGroups.empty())
primaryGroups.erase(primar yGroups.be gin(), primaryGroups.end());
if(!userDataObjects.empty( ))
userDataObjects.erase(user DataObject s.begin(), userDataObjects.end());
Thanks.
vector <wstring> primaryGroups;
//Erase all items in the group vector queueu and the user data object queue
if(!primaryGroups.empty())
primaryGroups.erase(primar
if(!userDataObjects.empty(
userDataObjects.erase(user
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Am I right in guessing that you are using vector<wstring> primaryGroups to manage the wstrings to which you have pointers in your ComboBox DataItemPtrs, alluded to in your other questions, lapucca? If so, please can you show how you create those wstrings and put their addresses into your Combobox?
ASKER
Hi Rstaveley, you're right. I now have 2 version of codes. I started out jusing using the vector to store the wstring but I'm getting Uninilize Memory(Rational Purify) everytime I push_back into that queueu and my application also randomly crashes.
I then start another version attempting to save the wstring in the comboBox SetItemData but had lots of problem setting up the pointers then casting back the pointers. The problem with the vector is posted here already. Please have a look at it if you would. Thanks. I'll happy to get any of these 2 version working.
I then start another version attempting to save the wstring in the comboBox SetItemData but had lots of problem setting up the pointers then casting back the pointers. The problem with the vector is posted here already. Please have a look at it if you would. Thanks. I'll happy to get any of these 2 version working.
>>I started out jusing using the vector to store the wstring but I'm getting Uninilize Memory(Rational Purify) everytime I push_back into that queueu and my
>>application also randomly crashes.
Rational Purify could be giving you a false error.
When you're code crahses, what does your stack look like.
You should check out your stack, and follow it back to your code, to see what exactly is causing the problem.
>>application also randomly crashes.
Rational Purify could be giving you a false error.
When you're code crahses, what does your stack look like.
You should check out your stack, and follow it back to your code, to see what exactly is causing the problem.
lapucca,
If you want your problem resolve, please post replies to comments posted by other experts.
If you want your problem resolve, please post replies to comments posted by other experts.
Let's see the calling code where you push your strings into primaryGroups.
See my comment in http:/Q_21833013.html
>>>> vector <CUserContextData> userDataObjects;
>>>> vector <wstring> primaryGroups;
You can make these container empty more easily by
userDataObjects.resize(0);
primaryGroups.resize(0);
However, that doesn't solve the problem you have with Purify for two reasons. First, "uninitialized memory" means that you are using variables as *input* argument or at the right side of an assignment, e. g.
(A)
int i;
int j = i; // assignment of uninitialized memory
(B)
int i;
anyfunc(i); // passing uninitialized memory to a function
(C)
class MyClass
{
int i;
wstring ws;
public:
MyClass() {} // i doesn't get initialized
// ws gets initialized cause there is constructor wstring::wstring
};
MyClass mc;
vector<MyClass> v;
v.push_back(mc); // push_back gets uninitialized memory from object mc
You problem most likely came from a case like (C). You defined LPWSTR instead of wstring and did *not* initialize these pointers to NULL in the constructor or *don't* supply a (default) constructor. Thus part(s) of the class were not initialized properly.
If you are using an a class member, the problem may occur in the class member as well
class MyClass
{
int i;
wstring ws;
public:
MyClass() {} // i doesn't get initialized
// ws gets initialized cause there is constructor wstring::wstring
};
class Superior
{
MyClass mc;
public:
};
Superior sup;
vector<Superior> v;
v.push_back(sup); // push_back gets uninitialized memory from object sup.mc
Regards, Alex
>>>> vector <wstring> primaryGroups;
You can make these container empty more easily by
userDataObjects.resize(0);
primaryGroups.resize(0);
However, that doesn't solve the problem you have with Purify for two reasons. First, "uninitialized memory" means that you are using variables as *input* argument or at the right side of an assignment, e. g.
(A)
int i;
int j = i; // assignment of uninitialized memory
(B)
int i;
anyfunc(i); // passing uninitialized memory to a function
(C)
class MyClass
{
int i;
wstring ws;
public:
MyClass() {} // i doesn't get initialized
// ws gets initialized cause there is constructor wstring::wstring
};
MyClass mc;
vector<MyClass> v;
v.push_back(mc); // push_back gets uninitialized memory from object mc
You problem most likely came from a case like (C). You defined LPWSTR instead of wstring and did *not* initialize these pointers to NULL in the constructor or *don't* supply a (default) constructor. Thus part(s) of the class were not initialized properly.
If you are using an a class member, the problem may occur in the class member as well
class MyClass
{
int i;
wstring ws;
public:
MyClass() {} // i doesn't get initialized
// ws gets initialized cause there is constructor wstring::wstring
};
class Superior
{
MyClass mc;
public:
};
Superior sup;
vector<Superior> v;
v.push_back(sup); // push_back gets uninitialized memory from object sup.mc
Regards, Alex
ASKER
My apology to everyone for not getting to this site the past day or so. My ass has been set on fire by my manager to get this done. I've gotten rid of the 2nd vector to store the value. I've gotten rid of trying to use the comboBox LPARAM to store my value as well. I came up with the 3rd version of the code which doesn't require heap memory or vector or LPARAM. I just got it working today.
1. I got rid of the delete code in my destructor as AXTER suggested and Rational Purify didn't complain about any memory leak that way so it works.
2. To rstaveley and AXTER, I still have the same problem with my CUserContextData vector when I call for CUserContextData .Push_Back() function. I'm still getting memory uninitilize when I run Rational Purify and it's making me very uncomfortable.
3. I will do more testing tomorrow to see if my application will crash to decide if Purify is putting out a false error message.
4. To rstaveley , I will post my code tomorrow when I get in the office.
5. Thanks to all the expert for helping me so far.
1. I got rid of the delete code in my destructor as AXTER suggested and Rational Purify didn't complain about any memory leak that way so it works.
2. To rstaveley and AXTER, I still have the same problem with my CUserContextData vector when I call for CUserContextData .Push_Back() function. I'm still getting memory uninitilize when I run Rational Purify and it's making me very uncomfortable.
3. I will do more testing tomorrow to see if my application will crash to decide if Purify is putting out a false error message.
4. To rstaveley , I will post my code tomorrow when I get in the office.
5. Thanks to all the expert for helping me so far.
ASKER
Ok, I think I will close this quesiton based on the fact I was asking about deleting and cleaning up the queue. I think Axter has answered this first so I will accept that for this question.
The memory Uninitilize is still a problem and I have opened up a separate quesiton for it, please see and comment on Q_21837305.html.
Alex, Thank you for the extensive input and example. I will checkit out and see that applies to my problem. Thank you to all experts's help.
The memory Uninitilize is still a problem and I have opened up a separate quesiton for it, please see and comment on Q_21837305.html.
Alex, Thank you for the extensive input and example. I will checkit out and see that applies to my problem. Thank you to all experts's help.
More then likely, there's a problem with CUserContextData destructor.