1 year ago

#236811

test-img

stonelazy

Python Memory not reclaimed after GC

Python in Mac: I was trying to understand gc.collect() and i wrote this code.
My expectation is that value of diff should be zero, but it isn't.

import gc
import numpy as np
import psutil

def create_and_destory():
    np.random.randn(10000)

if __name__ == '__main__':
    gc.collect()
    start_process = psutil.Process().memory_info().rss
    create_and_destory()
    gc.collect()
    end_process = psutil.Process().memory_info().rss
    diff = end_process - start_process
    print('diff value is: {}'.format(diff))

diff value is 36864

Couldn't quite get the reason for this behavior even after forceful trigger of garbage collection.
PS:
This returns a non-zero value only in MAC. In linux distros am getting a zero!

python

macos

garbage-collection

psutil

del

0 Answers

Your Answer

Accepted video resources