--
[ Picked text/plain from multipart/alternative ]
That's what I thought... in that case I need to figure out why calling
delete vector[element] crashes my mod!

On Jan 11, 2008 8:07 PM, Yahn Bernier <[EMAIL PROTECTED]> wrote:

> If the element type is a pointer:
>
> CUtlVector< CMyClass * > vecStuff;
>
> Then the underlying object will not be destructed, just the slot holding
> the ptr.
>
> If you do:
>
> CUtlVector< CMyClass > vecStuff;
>
> Then the object gets desctructed (but you also have to worry about
> implementing a copy constructor or operator =, etc. etc.)
>
> Safest thing in the CUtlVector< CMyClass * > case is to loop through the
> objects and call delete on each entry, and then call Purge/RemoveAll to
> free the memory used for the raw pointers.
>
> ~CUtlVector will automatically clean up the ptrs, but if you don't
> delete the objects in the CUtlVector< CMyClass * > case then you'll have
> a leak.
>
> Yahn
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Ronny
> Schedel
> Sent: Friday, January 11, 2008 11:50 AM
> To: [email protected]
> Subject: Re: [hlcoders] CUtlVector<*>... Memory management?
>
> Why you don't look at the code itself? In "Remove" you can see the
> element
> will be destroyed by the Destruct function. The Destruct function calls
> the
> Destructor of the element.
>
> Best regards
>
> Ronny Schedel
>
>
> > --
> > [ Picked text/plain from multipart/alternative ]
> > Am I right in assuming that if you have a vector of pointers, that
> point
> > to
> > things you create with "new", you have to either call delete on each
> > element
> > or use PurgeAndDeleteElements()? Because that's what I've been using
> up
> > until recently, where it seems that trying to delete elements from a
> > pointer
> > vector on destruction of whatever they are members of just causes the
> game
> > to crash with a memory error. Removing the calls to delete stop the
> crash,
> > but unless CUtlVector automatically cleans up your memory for you,
> won't
> > this just create MASSIVE memory leaks?  As far as I knew, CUtlVector
> > didn't
> > magically look after your memory for you... was I wrong?
> >
> > J
> > --
> >
> > _______________________________________________
> > To unsubscribe, edit your list preferences, or view the list archives,
> > please visit:
> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >
>
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives,
> please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives,
> please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
--

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to