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: modern_pascal_introduction.adoc
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -934,9 +934,17 @@ If you don't use the `override` keyword, the compiler will warn you that you're
934
934
935
935
### Remember to free the class instances
936
936
937
-
The class instances have to be manually freed, otherwise you get memory leaks. I advise using FPC `-gl -gh` options to detect memory leaks (see https://castle-engine.io/manual_optimization.php#section_memory ).
937
+
The class instances have to be manually freed, otherwise you get memory leaks.
938
938
939
-
Note that this doesn't concern raised exceptions. Although you do create a class when raising an exception (and it's a perfectly normal class, and you can create your own classes for this purpose too). But this class instance is freed automatically.
939
+
We advise to automatically detect memory leaks using:
940
+
941
+
- FPC command-line options `-gl -gh`
942
+
- Delphi `ReportMemoryLeaksOnShutdown := true`
943
+
- Castle Game Engine `detect_memory_leaks="true"` in `CastleEngineManifest.xml`
944
+
945
+
See https://castle-engine.io/memory_leaks for more information.
946
+
947
+
NOTE: You don't need to free the instances of raised exceptions. Although you do create an instance when raising an exception (and it's a perfectly normal class instance). But this class instance is freed automatically.
940
948
941
949
### How to free
942
950
@@ -978,7 +986,7 @@ We discourage from using this trick in your own code (for virtual or non-virtual
978
986
979
987
We advise using `FreeAndNil(A)` always, without exceptions, and never to call directly the `Free` method or `Destroy` destructor.
980
988
981
-
The _Castle Game Engine_ does it like that. It helps to keep a nice assertion that _all references are either nil, or point to valid instances_. But note that using `FreeAndNil(A)` doesn't *guarantee* this assertion. For example, if you copy the instance reference, and call `FreeAndNil(A)` on one copy, the other copy will be a non-nil dangling pointer.
989
+
The _Castle Game Engine_ does it like that. It helps to keep a nice assertion that _all references are either nil, or point to valid instances_. Though note that using `FreeAndNil(A)` doesn't *guarantee* this assertion, it only helps with this. For example, if you copy the instance reference, and call `FreeAndNil(A)` on one copy, the other copy will be a non-nil dangling pointer.
982
990
983
991
[source,pascal]
984
992
----
@@ -990,7 +998,7 @@ FreeAndNil(A);
990
998
991
999
More about dealing with this in the later section about _"Free notification"_.
992
1000
993
-
Still, `FreeAndNil(A)` takes care of the most trivial cases, so it's a good habit to use it IMHO. You will appreciate it when debuggging some errors, it is nice to easily observe _"``X`` is already freed, because `X` is `nil` now"_.
1001
+
Still, `FreeAndNil(A)` takes care of the most trivial cases, so it's a good habit to use it IMHO. You will appreciate it when debugging some errors, it is nice to easily observe _"``X`` is already freed, because `X` is `nil` now"_.
0 commit comments