Numb @njit @jitclass memory accumulation in loops

We are encountering a memory accumulation issue when using a Numba class to append arrays of floats to a list within a loop. Despite clearing the list before each iteration, the memory usage continues to grow proportionally with the loop size. Interestingly, this problem only arises when the class is implemented using Numba; it doesn’t occur with a standard Python class.

Any insights or suggestions on how to address this issue would be greatly appreciated. Thank you!

Here is a minimum working (or “bugging”) example. the out put is a positive number (i.e. more memory used after running the script). This is not the case if a normal pyhton class is used (remove the @jitclass() )

Tested for Specs:

OS: Linux SMP x86_64 | 22.04.1-Ubuntu

Numba: 0.59.1 | 0.58.1

Numpy: 1.26.4 | 1.24.1

Python:3.11.8 GCC 12.3.0 | 3.11.0 GCC 11.3.0

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import numba.experimental.jitclass as jitclass
import numba
import random
import numpy as np
import psutil
import os
@jitclass()
class testing:
points : numba.types.List(numba.types.Array(numba.types.float64, 1, "C"))
def __init__(self):
# Initialize point structure
self.points = [np.zeros(1)]
self.points.clear()
def compute(self):
# Clear possible previous points
self.points.clear()
l=random.randint(0,1000)
#l=10
for k in range(l):
self.points.append(np.array([np.float64(k)]))
return 0
a=testing()
process = psutil.Process(os.getpid())
base_memory_usage = process.memory_info().rss
for i in range(1000):
a.compute()
memory_usage = process.memory_info().rss
loop_memory_usage = memory_usage - base_memory_usage
print('RAM Used (GB):',loop_memory_usage/1e9)
</code>
<code>import numba.experimental.jitclass as jitclass import numba import random import numpy as np import psutil import os @jitclass() class testing: points : numba.types.List(numba.types.Array(numba.types.float64, 1, "C")) def __init__(self): # Initialize point structure self.points = [np.zeros(1)] self.points.clear() def compute(self): # Clear possible previous points self.points.clear() l=random.randint(0,1000) #l=10 for k in range(l): self.points.append(np.array([np.float64(k)])) return 0 a=testing() process = psutil.Process(os.getpid()) base_memory_usage = process.memory_info().rss for i in range(1000): a.compute() memory_usage = process.memory_info().rss loop_memory_usage = memory_usage - base_memory_usage print('RAM Used (GB):',loop_memory_usage/1e9) </code>
import numba.experimental.jitclass as jitclass
import numba
import random
import numpy as np
import psutil
import os

@jitclass()
class testing:
points : numba.types.List(numba.types.Array(numba.types.float64, 1, "C"))

    def __init__(self):
        # Initialize point structure
        self.points = [np.zeros(1)]
        self.points.clear()
    
    def compute(self):
    
        # Clear possible previous points
        self.points.clear()
        
        l=random.randint(0,1000)
        #l=10
        for k in range(l):
            self.points.append(np.array([np.float64(k)]))
        
        return 0

a=testing()

process = psutil.Process(os.getpid())
base_memory_usage = process.memory_info().rss
for i in range(1000):
a.compute()

memory_usage = process.memory_info().rss
loop_memory_usage = memory_usage - base_memory_usage

print('RAM Used (GB):',loop_memory_usage/1e9)

Thank you in advance!

PS: Note that we found a way to solve this by making a List of List instead of a List of Arrays but we do not understand why the issue occurs in the first place.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật