What's the easiest way to print the object in finalizer?

On 12 April 2016 at 14:16, Yichao Yu <[email protected]> wrote:

> On Tue, Apr 12, 2016 at 8:15 AM, FANG Colin <[email protected]> wrote:
> >  type C
> >    x::Symbol
> >
> >    function C(x::Symbol)
> >       c = new(x)
> >       finalizer(c, c->println(1, c, 2))
> >       c
> >     end
> >  end
> >
> > a = C(:x)
> > a = 1
> > gc()
> >
> > error in running finalizer: ErrorException("task switch not allowed from
> > inside gc finalizer")
>
> Since otherwise task switch can happen during any allocation and most
> people will find this surprising. (it's effectively impossible to
> create a task-switch-free block)
>
> >
> > However, it works if I manually call finalizer(a).
>
> It is less of a problem since you know when you do that.
>
> >
> > So, what's wrong with my usage of finalizer?
> >
> > Also, it seems I can only use finalizer(a) once, it doesn't work for the
> 2nd
> > time?
>
> It should, there's a bug that this causes the finalizers to be called
> less frequently https://github.com/JuliaLang/julia/pull/13995
>
> There was another bug that old object don't get finalized if you call
> `finalize` on it but I think it is fixed on both 0.4 and 0.5
> https://github.com/JuliaLang/julia/pull/13988
>

Reply via email to