piskvorky / bounter

Efficient Counter that uses a limited (bounded) amount of memory regardless of data size.
MIT License
934 stars 47 forks source link

Using .update has a memory leak #44

Open pashashocky opened 4 years ago

pashashocky commented 4 years ago

Description

Using .update method of a bounter counter with anothe counter has a memory leak.

Steps/Code/Corpus to Reproduce

printing would be useful, but here's the idea

def mem_leak():
    get_mem()
    c1 = bounter.bounter()
    c2 = bounter.bounter()
    for i in range(10**7):
        c1[random.randint(0,10)] += 1
        c2[random.randint(0,10)] += 1
    get_mem()
    c1.update(c2)
    get_mem()

def get_mem():
    print(psutils.Process(os.getpid()).memory_full_info().rss / 2 ** 20)  # in mb

get_mem()
mem_leak()
get_mem()
mem_leak()
get_mem()

Expected Results

Expect counters c1 and c2 to completely be destroyed from memory after mem_leak function exits.

Actual Results

Some memory remains used even after mem_leak function exits.

Versions

can't run versions, but: Linux 4.14 amzn linux x86 Python 3.6.6 Numpy 1.16.4 pandas 0.24.2 bounter 1.1.0

@mpenkov