[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...

Issue #10333 has been updated by Koichi Sasada.

9 messages 2014/10/07

[ruby-core:65712] [ruby-trunk - Bug #10387] [Open] Overwriting an array variable doesn't release referenced objects

From: andrew@...
Date: 2014-10-14 22:46:50 UTC
List: ruby-core #65712
Issue #10387 has been reported by Andrew Vit.

----------------------------------------
Bug #10387: Overwriting an array variable doesn't release referenced objects
https://bugs.ruby-lang.org/issues/10387

* Author: Andrew Vit
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
I narrowed down the following, but I'm not sure if the problem is mine or a bug:

~~~
require 'objspace'
GC.start

begin
  threads = []
  1000.times do
    threads << Thread.new { Random.new(10) }
  end
  threads.each &:join

  threads = []  # threads.clear
end

GC.start
puts ObjectSpace.count_tdata_objects
~~~

If I overwrite the threads variable with an empty array or nil, then 1000 Threads and 1000 Random objects remain in the heap.

However, if I run Array#clear to release the threads, then everything is released correctly.

I don't think this issue is related to threads necessarily, I was able to make it happen with regular objects, but it looks like you have to run a method on each object in the array, e.g.

~~~
  objects = []
  1000.times do
    objects << Random.new(10)
  end
  objects.each &:rand   # Random objects remain in memory with this line
  objects = []
~~~



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

In This Thread

Prev Next