You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -531,8 +531,22 @@ Note: Image display is a feature introduced experimentally in a fork of libui-ng
531
531
532
532
## Control Destruction and Memory Management
533
533
534
-
The ownership tree mechanism works well for most simple controls, allowing automatic memory deallocation through garbage collection.
535
-
However, due to the unpredictable timing of GC execution, it is advisable to explicitly destroy the main window before `UIng.uninit` performs its memory leak check when in doubt.
534
+
libui-ng is a C library, so normally the user is expected to manage memory manually.
535
+
However, it also provides some automatic memory management. The basic rule is: when a parent control is destroyed, all of its child controls are automatically destroyed as well.
536
+
537
+
For example, when destroy is called on controls such as Window, Box, Grid, Group, or Tab, it first destroys all child controls and then destroys itself.
538
+
539
+
In the case of a Window, there are two common situations:
540
+
541
+
When the user clicks the close (×) button on the title bar
542
+
In this case, on_closing is triggered, and Window#destroy is called automatically.
543
+
544
+
When on_should_quit is triggered
545
+
This means the entire program is about to quit. But here, Window#destroy is not called automatically, so the user needs to call it explicitly.
546
+
547
+
Crystal has garbage collection (GC) and provides a finalize hook when objects are freed. But since the timing of GC is unpredictable, combining it with libui-ng’s own automatic destruction can easily lead to issues. That’s why this project does not use finalize hooks.
548
+
549
+
It may seem a bit tricky, but understanding how libui-ng handles memory will help you avoid problems when building applications.
536
550
537
551
Some controls require specific destruction order for proper memory cleanup
0 commit comments