Project

General

Profile

Actions

Bug #18264

closed
Image

TracePoint leaks memory

Bug #18264: TracePoint leaks memory

Added by peterzhu2118 (Peter Zhu) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:105755]

Description

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.

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).

Image

Image Updated by peterzhu2118 (Peter Zhu) over 4 years ago Actions #1

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED

Image Updated by nobu (Nobuyoshi Nakada) over 4 years ago Actions #2 [ruby-core:105801]

Good catch.
An empty function was replaced with RUBY_TYPED_NEVER_FREE at 5c1b9b38d69d, but an empty free function means that the instance has nothing others to free, and it should equal RUBY_TYPED_DEFAULT_FREE.

Image Updated by peterzhu2118 (Peter Zhu) over 4 years ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12.


[Bug #18264] Fix memory leak in TracePoint

TracePoint leaks memory because it allocates a rb_tp_t struct
without ever freeing it (it is created with RUBY_TYPED_NEVER_FREE).

Image Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago Actions #4 [ruby-core:105958]

  • 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.

Image Updated by usa (Usaku NAKAMURA) over 4 years ago Actions #5 [ruby-core:106262]

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

ruby_2_7 1d4e037a8011ac05b4ede8cdf8263515ba0e095e merged revision(s) a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12.

Actions

Also available in: PDF Atom