• Re: Memory Leak problem while using MapViewOfFile

    From Ravindra Panchal@21:1/5 to Stephen Kellett on Wed Apr 6 02:48:58 2022
    same issue with my app. Have you got any clue on this memory leak, how to resolve ?


    On Thursday, July 11, 2002 at 6:13:37 PM UTC+5:30, Stephen Kellett wrote:
    In message <b5a71bcf.02071...@posting.google.com>, baskar <cbas...@yahoo.co.in> writes
    Hi,
    Using the following code to access the shared memory.

    *****************************************
    Object *dcM;
    dcM = (Object *) MapViewOfFile(hMapFile, // Handle to mapping object. >FILE_MAP_ALL_ACCESS, // Read/write permission
    0, // Max. object size.
    0, // Size of hFile.
    0); // Map entire file.
    dcM[0].method1() //Memory leak occors here >*****************************************
    Memory leak is occuring while calling method1. Need I to do anything to >handle this.
    People usually want to fix their memory leaks.
    A good tool for identifying and fixing memory leaks is Memory Validator.
    A 30 day evaluation can be found at http://www.softwareverify.com
    Regards
    Stephen
    --
    Stephen Kellett http://www.objmedia.demon.co.uk
    Object Media Limited C++/Java/Windows NT/Unix/X Windows/Multimedia
    If you are suffering from RSI, contact me for advice.
    Unsolicited email from spam merchants not welcome.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Ravindra Panchal on Wed Apr 6 22:15:39 2022
    On Wed, 6 Apr 2022 02:48:58 -0700 (PDT), Ravindra Panchal wrote:
    same issue with my app. Have you got any clue on this memory leak, how to resolve ?

    On Thursday, July 11, 2002 at 6:13:37 PM UTC+5:30, Stephen Kellett wrote:
    In message <b5a71bcf.02071...@posting.google.com>, baskar
    <cbas...@yahoo.co.in> writes
    Hi,
    Using the following code to access the shared memory.

    *****************************************
    Object *dcM;
    dcM = (Object *) MapViewOfFile(hMapFile, // Handle to mapping object. >>>FILE_MAP_ALL_ACCESS, // Read/write permission
    0, // Max. object size.
    0, // Size of hFile.
    0); // Map entire file.
    dcM[0].method1() //Memory leak occors here >>>*****************************************
    Memory leak is occuring while calling method1. Need I to do anything to >>>handle this.

    It's not a memory leak. It's how mapped memory work.

    The system does not initially allocate any memory. Only the address space.
    The system will dynamically allocate memory (in pages) as data is read/write from/to it. So, the more data is read/write from/to different part of the mapped memory, the more memory would actually be allocated. If all parts of
    the mapped memory is read, the system would end up allocating memory as
    large as the entire source of the mapped memory. IOTW, the system would only allocate memory as needed, and won't deallocate them until the mapped memory
    is destroyed.

    Mapped memory works similar to NTFS Sparse files in terms of storage space allocation. e.g. if a new 10MB sparse file is created without writing
    anything into it, it won't consume any storage space. It'll only consume storage space (in clusters) when a data is actually written into it. e.g. if the NTFS cluster size is 4K, and 1K data is written at start and at end of
    the file, the file would only consume 8K of storage space.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)