soegaard / sci

Racket libraries for scientific computing
18 stars 4 forks source link

Matrices not being freed when garbage collected #10

Closed massung closed 1 year ago

massung commented 2 years ago

Simple test:

  1. Start DrRacket
  2. In the expression area evaluate:
(require flomat)
(zeros 10000 10000)
  1. Observe ~700 MB of RAM is used (reported by DrRacket and whatever external RAM usage app your OS has)
  2. Click "Run" to clean everything up
  3. Observe RAM usage reported by DrRacket is back to initial levels
  4. External monitor shows memory still being used

My guess is that BLAS (or whatever is being wrapped) has a free_matrix function that needs to be called. Racket now has methods for automatically freeing the memory when the object is "freed" by the GC. See an example usage with my CSFML package: https://github.com/massung/racket-csfml/blob/master/graphics.rkt#L73

soegaard commented 1 year ago

Hi,

Is this still an issue?

I tried this loop in the terminal (macOS):

% racket84
Welcome to Racket v8.4 [cs].
> (require flomat)
> (let loop () (zeros 10000 10000) (loop))

The looked at memory usage in Activity Monitor and everything looked normal.

All memory allocations are done with malloc in atomic mode, so memory ought to be reclaimed automatically.

massung commented 1 year ago

Sorry, I missed this somehow. It totally looks good to me as well. Thanks for following up. Closing the issue.