-
Notifications
You must be signed in to change notification settings - Fork 614
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
What's the object ownership model? #544
Comments
Also, when I pass a string into a function, does libui copy the string or is the pointer expected to remain valid while the string is in use? |
I think this is a combination of libui and the native platform. Controls are based on The function Some controls are containers which can contain multiple children. These cases are handled in an implementation-specific way, but they all contain some array type of children and will destroy and free each child when the container is destroyed.
On any platform, a top-level window is owned by the system and the window cleans up itself when it's time to close the application. Part of that involves destroying the window's child which then kicks off a recursive series of child destruction as I described above.
This seems to be the case, except for instances where libui just passes the string directly to the platform, in which case the platform should be copying the string. Functions that return strings allocate memory for the result which needs to be freed with Hope this helps! |
So the string has to remain valid unless sent directly to the platform? How do we know when/if? |
Sorry, I see now that my response was a bit vague. Looking through the code, it seems that a copy is always made. It's just that sometimes libui passes your string pointer directly to the platform so the platform makes its own copy. I'm not the author so I could be wrong. It'd be worth doing a deeper-dive to ensure string copying is consistent. |
Ahh, no problem for the confusion. Thanks for the clarification! |
When I create a control and add it to a hierarchy, apparently the parent control takes ownership of the child and ensures that it gets cleaned up properly.
If I create a window and show it with
uiControlShow()
, it seems that libui takes ownership of the window. Maybe because it's been reparented to the conceptual screen?What happens then if I call
uiControlHide()
? Is the window deparented and therefore mine again, or does libui still keep it? What happens if I then show it once more?The text was updated successfully, but these errors were encountered: