CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: free memory?

  1. #1
    Join Date
    Jun 2001
    Posts
    126

    free memory?

    I am using a CStringArray in my program. I wish to not only free the memory associated with the pointers to the strings in the array (as is done with RemoveAt() and RemoveAll()), but I also wish to free the memory allocated to the actual strings. MSDN doesnt list a function for doing this. How do I do it manually?
    Thanx


  2. #2
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    Re: free memory?

    hi
    check the CString::FreeBuffer()
    Regards
    SKP

    Be sure to rate answers if it helped, to encourage them.

  3. #3
    Join Date
    Jun 2001
    Posts
    126

    Re: free memory?

    Do you mean CString::ReleaseBuffer()? I don't see a CString::FreeBuffer(). So, I would have to loop through the array, set each string to "", and call ReleaseBuffer() on each? If I understand it all right, I think that's what I need to do. Seems like there would be an easier way.


  4. #4
    Join Date
    Jun 2001
    Posts
    126

    Re: free memory?

    I'm just getting this back at the top. Could somebody tell me if there is an easier way?


  5. #5
    Join Date
    Oct 2000
    Posts
    127

    Re: free memory?

    Do you see memory leaks?
    Read in MSDN about CStringArray:
    "When a CString array is deleted, or when its elements are removed, string memory is freed as appropriate."


    It is nice to be important, but more important to be nice.
    It is nice to be important, but more important to be nice.

  6. #6
    Join Date
    Jun 2001
    Posts
    126

    Re: free memory?

    thanks, the RemoveAt() and RemoveAll() functions were CObjectArray base functions and for CObjectArray they do not free the objects. But I guess in the case of CStringArray the strings are deleted. Perhaps the memory leaks I thought I had were related to my CTypedPtrArray and not the string array.
    Appreciate the help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured