Discussion:
Memory Leak problem while using MapViewOfFile
(too old to reply)
Ravindra Panchal
2022-04-06 09:48:58 UTC
Permalink
same issue with my app. Have you got any clue on this memory leak, how to resolve ?
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.
JJ
2022-04-06 15:15:39 UTC
Permalink
Post by Ravindra Panchal
same issue with my app. Have you got any clue on this memory leak, how to resolve ?
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.

Loading...