Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

Native module memory management

$
0
0
Some native APIs (.e.g CHttpModule) provide a "Dispose" or "Terminate" method to enable the developer to perform any necessary cleanup. IScriptMapInfo does not provide such a method. When handling RQ_MAP_REQUEST_HANDLER (OnMapRequestHandler) one may wish to replace the existing script map with a new one by using the "SetScriptMap" method of the supplied IMapHandlerProvider interface. The new script map object would be an instance of a custom class derived from IScriptMapInfo. The MSDN example for "SetScriptMap" has the sample code calling the default "new" operator to create an instance of such a custom class. Needless to say, this will result in a memory leak (how would the IIS infrastructure know where the object was allocated: heap, stack, TLS, global, etc. or that it would need to call "delete" rather then "free" or "HeapFree"??). One option would be to use HttpContext::AllocateRequestMemory (perhaps in conjunction with a placement new operator) thus guaranteeing that the memory would be freed when the request is completed. Is this the correct way to handle this? Are there any other options? Is the sample code correct and I'm just missing something?

Viewing all articles
Browse latest Browse all 27852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>