This one took me a lot of testing to work out. I haven't written up a test project to confirm 100% exactly what circumstances causes the issue, but since changing from FastShareMem to FastMM4, my problems have stopped.
The project was a service application that dynamically loaded a number of DLLs (written by myself), called a procedure within, and then freed the DLL. Code from the project:
The service app and every DLL used FastShareMem as the first unit. Each DLL would use a TADOConnection passed as a parameter to create a new TADOQuery to look at data in a table. The TADOQuery was then freed. After about 1500 iterations, every attempt to open a TADOQuery either in a DLL or in the service application resulted in an exception "System resources exceeded". The OS (Windows 2000 Advanced Server) would need a reboot before things would work properly again. Task Manager was useless in trying to see which resouce, exactly, was being exceeded.
It took me ages to track down, and simply changing FastShareMem to FastMM4 fixed the issue instantly, without any other changes needed. The one exported procedure in each DLL has the same header.
I'm not sure why I was using FastShareMem for in the first place - it's the only project I've used it in.
What's it good for?
The project was a service application that dynamically loaded a number of DLLs (written by myself), called a procedure within, and then freed the DLL. Code from the project:
Code:
[b]type[/b]
TExternalCheck = [b]function[/b](ALocalConnection, ANexusConnection: TADOConnection; ATranNum,
AParam1, AParam2, AParam3, AParam4, AParam5,
AParam6, AParam7, AParam8, AParam9: String): Boolean; stdcall;
[b]var[/b]
Handle : THandle;
ExternalCheck : TExternalCheck;
DLLName : String;
[b]begin[/b]
[navy][i]// ... snip - outer loop for all DLLs ...
[/i][/navy] Log([purple]5[/purple], [teal]'Loading library '[/teal] + DLLName);
Handle := LoadLibrary(PChar(DLLName));
[b]try[/b]
[b]if[/b] Handle <> [purple]0[/purple] [b]then[/b]
[b]begin[/b]
@ExternalCheck := GetProcAddress(Handle, [teal]'CheckDocument'[/teal]);
[b]if[/b] @ExternalCheck <> [b]nil[/b] [b]then[/b]
ExternalCheck(LocalConnection, GetNexusConnection,
ATranNum, FieldByName([teal]'Param1'[/teal]).AsString,
FieldByName([teal]'Param2'[/teal]).AsString, FieldByName([teal]'Param3'[/teal]).AsString,
FieldByName([teal]'Param4'[/teal]).AsString, FieldByName([teal]'Param5'[/teal]).AsString,
FieldByName([teal]'Param6'[/teal]).AsString, FieldByName([teal]'Param7'[/teal]).AsString,
FieldByName([teal]'Param8'[/teal]).AsString, FieldByName([teal]'Param9'[/teal]).AsString);
[b]end[/b]
[b]else[/b]
LogFmt([purple]2[/purple], ATranNum, [teal]'Unable to load library %s'[/teal], [DLLName]);
[b]finally[/b]
Log([purple]5[/purple], [teal]'Unloading library '[/teal] + DLLName);
FreeLibrary(Handle);
[b]end[/b];
The service app and every DLL used FastShareMem as the first unit. Each DLL would use a TADOConnection passed as a parameter to create a new TADOQuery to look at data in a table. The TADOQuery was then freed. After about 1500 iterations, every attempt to open a TADOQuery either in a DLL or in the service application resulted in an exception "System resources exceeded". The OS (Windows 2000 Advanced Server) would need a reboot before things would work properly again. Task Manager was useless in trying to see which resouce, exactly, was being exceeded.
It took me ages to track down, and simply changing FastShareMem to FastMM4 fixed the issue instantly, without any other changes needed. The one exported procedure in each DLL has the same header.
I'm not sure why I was using FastShareMem for in the first place - it's the only project I've used it in.
What's it good for?