Actions
Bug #10387
closedOverwriting an array variable doesn't release referenced objects
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
Backport:
Description
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 = []
Actions
Like0
Like0Like0