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

Timer objects are not being gc'ed #3763

Closed
amitmurthy opened this issue Jul 19, 2013 · 5 comments
Closed

Timer objects are not being gc'ed #3763

amitmurthy opened this issue Jul 19, 2013 · 5 comments
Labels
I/O Involving the I/O subsystem: libuv, read, write, etc.
Milestone

Comments

@amitmurthy
Copy link
Contributor

function timercb(aw, status)
    println("Called")
end

t = TimeoutAsyncWork(timercb)
start_timer(t, 1.0, 1.0)
t = 1
gc()

I think it is better to treat timer objects as any other regular objects and clean them up as soon as any reference to them from user code is lost.

Same issue as #3567 I guess - just creating a new issue so that it is tracked.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 20, 2013

This was intentional also. It has also been used frequently to create graphics handler callbacks. Other callback based objects, such as processes work the same way. The object will be gc'd after the timer is stopped. (e.g. stop_timer(aw) or start_timer(t, 1.0, 0))

@amitmurthy
Copy link
Contributor Author

Can this behavior be set explicitly after the object has been created - something like gc_check(aw) which, if called will allow callback based objects to be deleted only if the underlying bound resource has been stopped/terminated.

The default behavior, would free the underlying resource as well as the object on gc.

@JeffBezanson
Copy link
Sponsor Member

I would reason about this as follows. If we stop timers that have no references to them, then all you have to do to make a "permanent" timer is keep a reference (e.g. in a global variable), which is very easy to do. But if we keep timers running even with no references, then if you forget to clean up on some code path, you are left with a running timer that is impossible to stop.

Now, it is a little strange for a timer to suddenly stop just because the GC kicked in, but given the asymmetry above (a situation that's easy to fix vs. impossible to fix), @amitmurthy might be right.

It is true that the current behavior was intentional, and we do take advantage of it in Tk. But it doesn't seem so bad to me just to keep a reference to the timer you need to keep running.

@Keno
Copy link
Member

Keno commented Jul 20, 2013

I disagree. This is very much akin to starting a Task. Should a task just cease to exit because we don't have a user-facing reference to it? Perhaps it would be better to instead add machinery to give you the ability to introspect all running timers?

@JeffBezanson
Copy link
Sponsor Member

I think this was settled by #11669. Now timers just run until you call close on them, end of story.

IanButterworth pushed a commit that referenced this issue May 4, 2024
Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: a0851bcfd
New commit: ed7a8dca8
Julia version: 1.12.0-DEV
Pkg version: 1.12.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@a0851bc...ed7a8dc

```
$ git log --oneline a0851bcfd..ed7a8dca8
ed7a8dca8 add note about `activate -` to command help (#3888)
c26ad23e9 Use `Base.format_bytes` (#3763)
c59b37ffd add hint kwarg to complete_line (#3886)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I/O Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

4 participants