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(primaryGroups.begin(), primaryGroups.end());
            if(!userDataObjects.empty())
                  userDataObjects.erase(userDataObjects.begin(), userDataObjects.end());
Thanks.
lapuccaAsked:
Who is Participating?
 
AxterCommented:
Hi lapucca,
> //Erase all items in the group vector queueu and the user data object queue
>           if(!primaryGroups.empty())
>                primaryGroups.erase(primaryGroups.begin(<wbr/>),
> primaryGroups.end());
>           if(!userDataObjects.empty())
>                userDataObjects.erase(userDataObjects.be<wbr/>gin(),
> userDataObjects.end());

The above code is not required.  The vector destructor will do the cleanup automatically, so you can delete the above code entirely from your destructor.

David Maisonave (Axter)
Cheers!
0
 
AxterCommented:
FYI:
More then likely, there's a problem with CUserContextData destructor.
0
 
rstaveleyCommented:
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?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lapuccaAuthor Commented:
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.
0
 
AxterCommented:
>>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.
0
 
AxterCommented:
lapucca,

If you want your problem resolve, please post replies to comments posted by other experts.
0
 
rstaveleyCommented:
Let's see the calling code where you push your strings into primaryGroups.
0
 
rstaveleyCommented:
See my comment in http:/Q_21833013.html 
0
 
itsmeandnobodyelseCommented:
>>>>    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
0
 
lapuccaAuthor Commented:
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.
0
 
lapuccaAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.