[fpc-pascal] TIniFile crash/memory loss

José Mejuto joshyfun at gmail.com
Fri Apr 1 12:28:33 CEST 2011


Hello FPC-Pascal,

Friday, April 1, 2011, 9:58:24 AM, you wrote:

MVC> 2. Cache the updates, and make sure they are written when the instance is destroyed.
MVC>     This is the current behaviour. It works fast, but the corner case you encountered
MVC>     (an error when updating the file in the destructor) is now an issue.
MVC> Going back to 1 is not an option.
MVC> For case 2, I am inclined to say that the destructor must always succeed.
MVC> Errors in destructors are very ugly to trap.

As the destructor must allways success...:

procedure TObject.Free;
begin
  try
    if Assigned(Self) then Self.Destroy;
  except
  end;
end;

If the free would write it must ensures expected job is done, if not
an exception must be raised. The other possibility is to never write
on free or the job is not deterministic as it could be written or not
and you will not be notified about it. In other words, or UpdateFile
is mandatory to write or the exception must be raised in the case of
error in free.

An exception in free is an extreme rare condition, but it could
happend, and is better that your software stops to work than notify 2
years later that your 2 zillions of INI files were not written at all
because the user write a non valid file path.

-- 
Best regards,
 José




More information about the fpc-pascal mailing list