Why do i get an “EPrivilege - Privileged instruction” when I execute this procedure instead of Access Violation?
{$Warnings OFF}
procedure TFrmMyTest.mnuCrashMeClick(Sender: TObject);
var t: TStringList;
begin
FreeAndNil(t);
end;
{$Warnings ON}
I know that I try to free an object that points randomly in memory. But I expect to get an access violation and not “Privileged instruction”.
(Don’t worry I don’t intend to use the code above in a real program.)
Sometimes you will get an access violation and sometimes you will get
EPrivilegeand no doubt there are other modes of failure. And even sometimes the code will appear to work and the crash will happen later. It all depends on what value happens to be intwhen you callFreeon it.