View Issue Details

IDProjectCategoryView StatusLast Update
0028895FPCRTLpublic2016-03-29 09:56
ReporterThaddy de KoningAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.1.1Product Build 
Target Version3.1.1Fixed in Version3.0.2 
Summary0028895: feature request for DisposeAndNil (follow-up on 28891)
DescriptionMaybe something like this can be added to the rtl (either system or sysutils):

procedure DisposeAndNil(var p);
var
  temp:Pointer;
begin
  temp := Pointer(p);
  Pointer(P):=nil;
  Dispose(temp);
end;
 
This is like FreeAndNil but for New/Dispose.
I still think the dispose behavior is counter-intuitive. This may help.
TagsNo tags attached.
Fixed in Revision33377
FPCOldBugId
FPCTarget
Attached Files

Activities

Michael Van Canneyt

2016-03-27 10:35

administrator   ~0091467

Dispose can only be used on typed pointers, this code does not even compile.

Thaddy de Koning

2016-03-29 06:50

reporter   ~0091557

Last edited: 2016-03-29 06:59

View 4 revisions

It does compile -at least in mode Delphi -, it is tested and it is an exact equivalent of FreeAndNil. But it is a minor request. I'll keep it in my own code for KOL.
I have no problems if it is still refused.

The KOL equivalent used to be Free_And_Nil (for objects, not classes) but does the same since 2004. In my development branch it is now the above code.

Michael Van Canneyt

2016-03-29 09:30

administrator   ~0091561

You don't give me credit :-)

I tested that before posting:

/usr/local/bin/ppcx64 -Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. -FU../../rtl/units/x86_64-linux -Cg -dx86_64 -Fi../objpas/sysutils ../unix/sysutils.pp
sysutils.inc(171,21) Error: use of NEW or DISPOSE is not possible for untyped pointers
sysutils.pp(1556) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Michael Van Canneyt

2016-03-29 09:35

administrator   ~0091562

However, it bugged me. So I switched to freemem and then it compiles.

Jonas Maebe

2016-03-29 09:49

manager   ~0091564

I think this should be removed again. Dispose() finalizes the pointed data before freeing it (in case of e.g. a pointer to a record with managed fields), while this routine does not (and cannot). That is the main difference between Dispose and Freemem.

Michael Van Canneyt

2016-03-29 09:56

administrator   ~0091566

I have renamed it to FreeMemAndNil. The functionality is useful by itself.

Issue History

Date Modified Username Field Change
2015-10-23 10:42 Thaddy de Koning New Issue
2016-03-27 10:35 Michael Van Canneyt Note Added: 0091467
2016-03-27 10:35 Michael Van Canneyt Status new => resolved
2016-03-27 10:35 Michael Van Canneyt Resolution open => won't fix
2016-03-27 10:35 Michael Van Canneyt Assigned To => Michael Van Canneyt
2016-03-29 06:50 Thaddy de Koning Note Added: 0091557
2016-03-29 06:50 Thaddy de Koning Status resolved => feedback
2016-03-29 06:50 Thaddy de Koning Resolution won't fix => reopened
2016-03-29 06:51 Thaddy de Koning Note Edited: 0091557 View Revisions
2016-03-29 06:59 Thaddy de Koning Note Edited: 0091557 View Revisions
2016-03-29 06:59 Thaddy de Koning Note Edited: 0091557 View Revisions
2016-03-29 09:30 Michael Van Canneyt Note Added: 0091561
2016-03-29 09:35 Michael Van Canneyt Fixed in Revision => 33377
2016-03-29 09:35 Michael Van Canneyt Note Added: 0091562
2016-03-29 09:35 Michael Van Canneyt Status feedback => resolved
2016-03-29 09:35 Michael Van Canneyt Fixed in Version => 3.0.2
2016-03-29 09:35 Michael Van Canneyt Resolution reopened => fixed
2016-03-29 09:35 Michael Van Canneyt Target Version => 3.1.1
2016-03-29 09:49 Jonas Maebe Note Added: 0091564
2016-03-29 09:56 Michael Van Canneyt Note Added: 0091566