From b16a96c352843539b2fdb5a9eb572e12cb7ed4cc Mon Sep 17 00:00:00 2001 From: vlado Date: Tue, 7 May 2019 12:33:45 -0600 Subject: [PATCH] Rename release_all -> empty_cache and provide documentation --- python/mxnet/context.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/mxnet/context.py b/python/mxnet/context.py index 1ca105146d01..25279f1c49f8 100644 --- a/python/mxnet/context.py +++ b/python/mxnet/context.py @@ -145,7 +145,20 @@ def default_ctx(cls, val): cls._default_ctx.value = val #pylint: enable=no-self-argument - def release_all(self): + def empty_cache(self): + """Empties the memory cache for the current contexts device. + + MXNet utilizes a memory pool to avoid excessive allocations. + Calling empty_cache will empty the memory pool of the contexts + device. This will only free the memory of unreferenced data. + + Examples + ------- + >>> ctx = mx.gpu(0) + >>> arr = mx.nd.ones((200,200), ctx=ctx) + >>> del arr + >>> ctx.empty_cache() # forces release of memory allocated for arr + """ dev_type = ctypes.c_int(self.device_typeid) dev_id = ctypes.c_int(self.device_id) check_call(_LIB.MXStorageReleaseAll(dev_type, dev_id))