Skip to content

Commit d2263fd

Browse files
committed
Extend memory leaks notes, mention Delphi ReportMemoryLeaksOnShutdown, CGE detect_memory_leaks="true"
1 parent 6c9f1e8 commit d2263fd

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

modern_pascal_introduction.adoc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,17 @@ If you don't use the `override` keyword, the compiler will warn you that you're
934934

935935
### Remember to free the class instances
936936

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.
938938

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.
940948

941949
### How to free
942950

@@ -978,7 +986,7 @@ We discourage from using this trick in your own code (for virtual or non-virtual
978986

979987
We advise using `FreeAndNil(A)` always, without exceptions, and never to call directly the `Free` method or `Destroy` destructor.
980988

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.
982990

983991
[source,pascal]
984992
----
@@ -990,7 +998,7 @@ FreeAndNil(A);
990998

991999
More about dealing with this in the later section about _"Free notification"_.
9921000

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"_.
9941002

9951003
### Manual and automatic freeing
9961004

0 commit comments

Comments
 (0)