ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
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:52072]  [Ruby master Bug#20311] Struct.new("A") memory leak?
Date: Thu, 29 Feb 2024 11:45:33 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-107073.20240229114532.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).


> rb_const_remove needs to take care of it when the removed constant is a class or module?

The problem is that it's a set:

```c
st_insert(vm->defined_module_hash, (st_data_t)module, (st_data_t)module);
```

So if a module is added twice, you need to remove it from the set if it's removed twice... I'll see if I can do that.

But I also wonder why we have this root in the first place, I'd think these get marked from being constants in `::Object`.

----------------------------------------
Bug #20311: Struct.new("A") memory leak?
https://bugs.ruby-lang.org/issues/20311#change-107073

* 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/

  parent reply	other threads:[~2024-02-29 11:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 12:03 [ruby-dev:52069] [Ruby master Bug#20311] Struct.new("A") memory leak? MaxLap (Maxime Lapointe) via ruby-dev
2024-02-28 13:28 ` [ruby-dev:52070] " byroot (Jean Boussier) via ruby-dev
2024-02-28 16:36 ` [ruby-dev:52071] " nobu (Nobuyoshi Nakada) via ruby-dev
2024-02-29 11:45 ` byroot (Jean Boussier) via ruby-dev [this message]
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

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-107073.20240229114532.8409@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-dev@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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 read-only IMAP folder(s) and NNTP newsgroup(s).