From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 9991C1F4C0 for ; Sun, 27 Oct 2019 20:41:36 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B7CB412097C; Mon, 28 Oct 2019 05:41:25 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4B278120977 for ; Mon, 28 Oct 2019 05:41:24 +0900 (JST) Received: by filter0187p3mdw1.sendgrid.net with SMTP id filter0187p3mdw1-18277-5DB600F7-25 2019-10-27 20:41:27.665007333 +0000 UTC m=+511256.244837760 Received: from herokuapp.com (unknown [3.85.110.205]) by ismtpd0054p1iad1.sendgrid.net (SG) with ESMTP id jrUtxRkFT4mKtutjMEyRGA for ; Sun, 27 Oct 2019 20:41:27.625 +0000 (UTC) Date: Sun, 27 Oct 2019 20:41:27 +0000 (UTC) From: sacrogemini@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71164 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16278 X-Redmine-Issue-Author: cristiangreco X-Redmine-Sender: cristiangreco X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?3ePCKlVP1UNPhPOu8giSKlJlQEOFyufaA6HnRnFYbTMVq1t1=2F8pWfjYbq6ugmy?= =?us-ascii?Q?Rhlq+56uNOmkNTOgkpKLZC2J5h53QoN738VHxy8?= =?us-ascii?Q?y0yNW6EWvx6QLSodDVMeiSE2LByRDOHAHvSd3dh?= =?us-ascii?Q?RLECO=2Fa6oi6SbKhO7LHPHUbUouDEcCNpR66i7l1?= =?us-ascii?Q?7qLxrf534DAqHxoi9o2TlZvtu0qJDBr9UpQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95571 Subject: [ruby-core:95571] [Ruby master Bug#16278] Potential memory leak when an hash is used as a key for another hash X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16278 has been updated by cristiangreco (Cristian Greco). Thanks both @jeremyevans0 @alanwu for the rich and clear explanations! ---------------------------------------- Bug #16278: Potential memory leak when an hash is used as a key for another hash https://bugs.ruby-lang.org/issues/16278#change-82352 * Author: cristiangreco (Cristian Greco) * Status: Rejected * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Hi, I've been hitting what seems to be a memory leak. When an hash is used as key for another hash, the former object will be retained even after multiple GC runs. The following code snippet demonstrates how the hash `{:a => 1}` (which is never used outside the scope of `create`) is retained even after 10 GC runs (`find` will look for an object with a given `object_id` on heap). ```ruby # frozen_string_literal: true def create h = {{:a => 1} => 2} h.keys.first.object_id end def find(object_id) ObjectSpace.each_object(Hash).any?{|h| h.object_id == object_id} ? 1 : 0 end leaked = create 10.times do GC.start(full_mark: true, immediate_sweep: true) end exit find(leaked) ``` This code snippet is expected to exit with `0` while it exits with `1` in my tests. I've tested this on multiple recent ruby versions and OSs, either locally (OSX with homebrew) or in different CIs (e.g. [here](https://github.com/cristiangreco/ruby-hash-leak/commit/285e586b7193104989f59b92579fe8f25770141e/checks?check_suite_id=278711566)). Can you please help understand what's going on here? Thanks! -- https://bugs.ruby-lang.org/