Skip to content

Best practices for updating array parameters and buffer management #16904

Answered by jakevdp
hamzamerzic asked this question in Q&A
Discussion options

You must be logged in to vote
  1. When does self.params get deallocated from its current device?
  2. How does the garbage collector (gc) interact with self.params? Is there a dependency on gc for initiating memory cleanup on the device?

In short, assuming your code is not wrapped in jit, the way to think of it is like this,

  • self.params references some Python object that we might call obj – Python maintains a refcount on obj that has a value of at least 1, becuse self.params currently references it.
  • when you write self.params = new_params, the refcount of obj is decreased by 1. If self.params is the only reference to obj, then the refcount will become zero.
  • at some point later (not necessarily immediately) Python's garbag…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hamzamerzic
Comment options

@jakevdp
Comment options

Answer selected by hamzamerzic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants