CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    37

    [COM] If memory allocated by malloc() don't freed?

    What problems are there if memory allocated by malloc(), C-Library function, is not freed?
    A COM program uses old C module using C-Library function. But the module has some problems on memory allocation and deallocation. Sometimes it doesn't deallocate heap memory.
    Does COM library automatically free this memory when an instance is destroyed?

    I'm confused with thread & COM instance.
    I know that a thread doesn't release own heap memory when destroyed.
    A COM instance doesn't too?

    I'll wait for your kindness.


    A programmer who loves Goethe.

  2. #2
    Join Date
    Apr 1999
    Location
    Toronto, ON
    Posts
    713

    Re: [COM] If memory allocated by malloc() don't freed?

    You must free memory manualy by free()


  3. #3
    Guest

    Re: [COM] If memory allocated by malloc() don't freed?

    It depends how you implement your COM. Most of the time, COM allocates memory space and gives it to the caller, the caller is responsible for deleting it.
    In your case, I think COM returns a allocated area of memory to COM client, and inside the client you should release the allocated memory.

    Hope it helps. Adios.

    Duy D. Tran
    [email protected]




  4. #4
    Join Date
    May 1999
    Posts
    35

    Re: [COM] If memory allocated by malloc() don't freed?

    If you dont free memory allocated by malloc() .you will get memory leak when you leav the function body.So if you realy wants no memory leacks in your app better to free all the memory.


  5. #5
    Guest

    Re: [COM] If memory allocated by malloc() don't freed?

    Memory that is passed between COM clients and servers must be allocated using CoTaskMalloc as the COM remoting architecture will expect it.

    COM makes no attempt to clean up objects or any of the resources allocated by the object, it is up to the object to clean up these resources when it's ref count goes to zero. If the object is in an out-of-process server then its resources will be reclaimed by the operating system when the server process closes.

    Small memory leaks are acceptable if they only happen occasionaly and the server is not expected run for extended periods (remember you have 2GB virtual memory per process), but the cumulative effect of repeated memory leaks on performance can be devistating due to the extra pageing to and from swap file required.


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