When a process has finished with the file-mapping object, it should destroy all file views in its address space by using the UnmapViewOfFile function for each file view. This function invalidates the pointer to the process's virtual address space. If any of the pages of the file view have changed since the view was mapped, the system writes the changed pages of the file to disk using caching. To commit the data to disk immediately, call the FlushViewOfFile function before unmapping the file view.
You must call the CloseHandle function to first close the file-mapping object and then close the file on disk. These calls to CloseHandle succeed even when there are file views that are still open. However, leaving file views mapped causes memory leaks.