yuxihu commented on issue #14805: Fix memory leak when executing monitor callback in GraphExecutor URL: https://github.com/apache/incubator-mxnet/pull/14805#issuecomment-488072326 > Hi, @yuxihu. > > Could you please tell me where the memory of NDArray is freed? > > I met a similar problem. I found the function [`AllocateNDArrayCopy`](https://github.com/apache/incubator-mxnet/blob/master/src/operator/custom/custom.cc#L46) in Custom Operator allocates new NDArray, but I do not know where the NDArray is released. > > Thank you! @wkcn It turned out that the higher level language (e.g. Python) needs to free the memory for the issue I was trying to fix with this PR. More information can be found [here](https://github.com/apache/incubator-mxnet/issues/10692#issuecomment-487698584). We create a (Python) NDArray with the raw pointer created before calling the callback. The Python NDArray will delete the pointer once it is out of scope. This is how we do it in [Monitor](https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/monitor.py#L70) class. The memory is freed from [here](https://github.com/apache/incubator-mxnet/blob/225f71f744ac5e7bd29868b6d3ba0e4fe2527c43/python/mxnet/_ctypes/ndarray.py#L51).
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services