From: "byroot (Jean Boussier) via ruby-dev" <ruby-dev@ml.ruby-lang.org>
To: ruby-dev@ml.ruby-lang.org
Cc: "byroot (Jean Boussier)" <noreply@ruby-lang.org>
Subject: [ruby-dev:52070] [Ruby master Bug#20311] Struct.new("A") memory leak?
Date: Wed, 28 Feb 2024 13:28:31 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-107049.20240228132831.8409@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20311.20240228120314.8409@ruby-lang.org>
Issue #20311 has been updated by byroot (Jean Boussier).
I had a quick look at this using `ObjectSpace.dump_all`, and it appears that these classes are being retained in the VM root:
```ruby
require 'objspace'
3.times do
puts ObjectSpace.dump(Struct.new("A"))
Struct.send(:remove_const, :A)
end
GC.start
ObjectSpace.dump_all(output: File.open("/tmp/heap.json", "w+"))
```
```
{"address":"0x102bc33f8", "type":"CLASS", ....
{"address":"0x102bc3218", "type":"CLASS", ....
{"address":"0x102bc3038", "type":"CLASS", ....
```
```
$ rg -F '"0x102bc3218"' /tmp/heap.json
1:{"type":"ROOT", "root":"vm", "references":[..., "0x102bc3218"
$ rg -F '"0x102bc33f8"' /tmp/heap.json
1:{"type":"ROOT", "root":"vm", "references":[..., "0x102bc33f8"
```
----------------------------------------
Bug #20311: Struct.new("A") memory leak?
https://bugs.ruby-lang.org/issues/20311#change-107049
* Author: MaxLap (Maxime Lapointe)
* Status: Open
* ruby -v: 3.3.0
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
The following code gives the impression of a memory leak.
```
10.times do
5000.times do
Struct.new("A")
Struct.send(:remove_const, :A)
end
GC.start
puts `ps -o rss= -p #{$$}`.to_i
end
```
```
27868
35324
43400
51472
58676
66144
73764
81196
88512
95752
```
Is there another location where the struct gets set that I need to clear up for the GC free the memory?
Happens in 3.2.2, 3.2.3, 3.3.0, 3.3-head, ruby-head.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2024-02-28 13:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 12:03 [ruby-dev:52069] " MaxLap (Maxime Lapointe) via ruby-dev
2024-02-28 13:28 ` byroot (Jean Boussier) via ruby-dev [this message]
2024-02-28 16:36 ` [ruby-dev:52071] " nobu (Nobuyoshi Nakada) via ruby-dev
2024-02-29 11:45 ` [ruby-dev:52072] " byroot (Jean Boussier) via ruby-dev
2024-02-29 11:47 ` [ruby-dev:52073] " byroot (Jean Boussier) via ruby-dev
2024-02-29 12:07 ` [ruby-dev:52074] " byroot (Jean Boussier) via ruby-dev
2024-02-29 14:59 ` [ruby-dev:52075] " byroot (Jean Boussier) via ruby-dev
2024-03-01 6:03 ` [ruby-dev:52077] " nobu (Nobuyoshi Nakada) via ruby-dev
2024-03-01 7:01 ` [ruby-dev:52078] " nobu (Nobuyoshi Nakada) via ruby-dev
2024-03-01 7:23 ` [ruby-dev:52079] " byroot (Jean Boussier) via ruby-dev
2024-03-21 6:58 ` [ruby-dev:52081] " naruse (Yui NARUSE) via ruby-dev
2024-07-08 2:12 ` [ruby-dev:52092] " nagachika (Tomoyuki Chikanaga) via ruby-dev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-107049.20240228132831.8409@ruby-lang.org \
--to=ruby-dev@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).