ModularM
Modular3y ago
21 replies
zverianskii

memory leak with DynamicVector

What is the right way to avoid memory leaks? From docs we see that DynamicVector doesn’t call elements destructors. Decorators supposed to create destructor but as far as I can tell you can’t use it manually. So what is the proper way to clean up in the and of the each step in the cycle?

from utils.vector import DynamicVector # decorators supposed to create __del__? @value @register_passable("trivial") struct Point: var row: Int var col: Int var val: Int8 fn main(): for i in range(1000000): var vec = DynamicVector[Point](1000) for j in range(1000): vec.push_back(Point(0,0,0)) # this code doesn’t compile: # for j in range(1000): # vec[j].__del__()
Was this page helpful?