Issue #18264 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE

ruby_3_0 75e74993916e9abda1a74164fed5b59fc3d9b7ce merged revision(s) a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12.

----------------------------------------
Bug #18264: TracePoint leaks memory
https://bugs.ruby-lang.org/issues/18264#change-94505

* Author: peterzhu2118 (Peter Zhu)
* Status: Closed
* Priority: Normal
* Backport: 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE
----------------------------------------
# GitHub PR: https://github.com/ruby/ruby/pull/5008

TracePoint leaks memory because it allocates a `rb_tp_t` struct without ever freeing it (it is created with `RUBY_TYPED_NEVER_FREE`). This is reproducible on all maintained Rubies (2.6.8, 2.7.4, 3.0.2, master) on Ubuntu 20.04.

The follow string demonstrates the issue.

```ruby
100.times do
  10000.times do
    TracePoint.new(:line) {}
  end

  # Output the Resident Set Size (memory usage, in KB) of the current Ruby process
  puts `ps -o rss= -p #{$$}`
end
```

We can see the leak through the following graph of the Resident Set Size (RSS) comparing the branch vs. master (at commit 6b9285e8d45e88c5b014b8428520ffa2401789ad).

![](https://user-images.githubusercontent.com/15860699/138502310-007bd725-d364-4be4-b128-ebdb859b8613.png)




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>