GithubHelp home page GithubHelp logo

Comments (2)

rodrigocfd avatar rodrigocfd commented on May 19, 2024

This is a very interesting problem. Yes, you understanding is correct: there is a circular reference happening though all that chain, which can be summarized as: window has closures which have window.

I noticed you are only allowed to register event handlers before the HWND has been created. I wonder, would it make any sense that, when the HWND is destroyed, you drop all the event handlers?

Yes, it does make sense, and that's indeed what I implemented. The only caveat is that this dropping – ultimately calling Vec::clear to release all closures – must be done after the very last possible message to be processed, which according to our much cherished Raymond Chen (and my own observations) is WM_NCDESTROY. And not just that: the cleanup must happen only after any user-defined WM_NCDESTROY have been executed themselves, otherwise they would be lost (with their potential cleanups, leading to leaks). Oh and to make it even more robust, the struct pointer is cleaned before the closures cleanup, so any weird messages after WM_NCDESTROY won't be handled.

Although I’m not sure how well that would work with dynamic creation and destruction of controls

Not really a concern – dynamically created controls are not allowed by the library (at least by now), because, as you said, most events belong to the parent window, and handling that scenario has proven to be extremely complex. Maybe I'll implement this in the future, but I know it would require a complete rework of the message plumbing.

Your example now runs fine, and I found no side-effects on any of my own programs. Please let me know if this solution works for you.

Thank you very much for your time and effort.

from winsafe.

Hawk777 avatar Hawk777 commented on May 19, 2024

Everything you said makes sense to me; thank you for all your work on winsafe!

from winsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.