Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird finalizer bug: finalize() does not execute installed finalizer function sometimes #13986

Closed
amitmurthy opened this issue Nov 14, 2015 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior GC Garbage collector

Comments

@amitmurthy
Copy link
Contributor

Ran into this while working on DistributedArrays. A somewhat reduced test case is described here:

addprocs(1)

callme(f) = @schedule println("CALLED!")

type Foo{T,N} <: AbstractArray{T, N}
    a::RemoteRef
    Foo(n) = (f=new(remotecall(ones, 2, n)); finalizer(f, callme); f)
end

Base.getindex(d::Foo, i::Int) = d.a[i]
Base.getindex(d::Foo, i::Int...) = d.a[i...]
Base.getindex(d::Foo) = d[1]

Base.size(d::Foo) = size(fetch(d.a))

f1 = Foo{Float64, 2}((55, 55));

f1 == f1

finalize(f1)

The finalizer on Foo is NOT called if the equality test f1==f1 is performed on Foo sizes greater than (54,54)

Examples:

Called with equality test and sizes (54, 54) and (54, 55).
(54,55) is not predictable - sometimes it is called and sometimes not.

julia> f1 = Foo{Float64, 2}((54, 54));

julia> f1 == f1
true

julia> finalize(f1)
CALLED!


julia> f1 = Foo{Float64, 2}((54, 55));

julia> f1 == f1
true

julia> finalize(f1)
CALLED!

NOT called with equality test and size (55,55)

julia> f1 = Foo{Float64, 2}((55, 55));

julia> f1 == f1
true

julia> finalize(f1)

Called with equality test commented out.

julia> f1 = Foo{Float64, 2}((55, 55));

julia> #f1 == f1
       finalize(f1)
CALLED!

@amitmurthy amitmurthy added bug Indicates an unexpected problem or unintended behavior GC Garbage collector labels Nov 14, 2015
@ViralBShah
Copy link
Member

Cc @carnaval

@yuyichao
Copy link
Contributor

The reason is that the finalizer is moved to the list for the old objects and we were not checking that list for finalizers when you explicitly call the finalize...... The "weird" effect you are seeing is basically promotion to the old gen...

Fixed in #13988

yuyichao added a commit that referenced this issue Nov 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior GC Garbage collector
Projects
None yet
Development

No branches or pull requests

3 participants