I have a Cocoa console test application I’ve built/run in various previous versions of Elements. Rather than the main program being inside a class method called Program.main, it’s just the code after the implementation keyword in Program.pas. It looks like the snippet below. If I build and try to run (either Start or Start without debugging) I get “Exception: EXC_BAD_ACCESS (code=1, address=0x20)” in VS with the pointer on the var theFoo := new Foo; line. If I remove the using autoreleasepool do begin end around the code, the exception goes away.
begin
using autoreleasepool do begin
var theFoo := new Foo;
...
end;
end;
we’ll need a mor complete test case. i cant repro this with just:
namespace ConsoleApplication18;
interface
uses
Foundation;
type
Foo = class
end;
implementation
begin
using autoreleasepool do begin
var theFoo := new Foo;
end;
end.
FYI, the issue was apparently in my own code. I was stepping over a dynamic array bound in a class I’d written. I’m guessing that, without the autoreleasepool, it was just masked by tearing down the entire application, but that with autoreleasepool the class was freed earlier so the access violation appeared. It didn’t give any sensible indication of where the problem was, so I eventually found it using an interval search where I commented out sections of code until I isolated the issue.
The problem was only manifested on release, not when the actual bounds violation took place.