Thoughts from Dan Miser RSS 2.0
 Thursday, April 28, 2005
If you use the ChildRDM architecture available in Delphi 6 in %DELPHI%\Demos\Midas\SharedConn, there is a possibility of the server hanging in memory after all clients have exited. This really only applies if you are using a COM object in another DLL and using that COM object as a ChildRDM in your main server EXE.

Debugging the problem, I found that there were still references to the external DLL, and that the CPU view was showing me that the EXE was repeatedly trying to enter a critical section, but not being able to do so. If you look at the destruction code for TDataModule, you'll see that it tries to lock access to the DataModule. Well, if you rely on Delphi to get rid of internally stored interface references when they go out of scope, it will be too late to reclaim the external DLL. The solution is as follows:

Create an overridden BeforeDestruction method in the main RDM. In that RDM, set all of your ChildRDM interface references to nil in order to explicitly release the COM objects. Then, make a call to CoFreeUnusedLibraries (found in ActiveX.pas). This will release the DLL, if the COM subsystem says it's OK to do so. However, I found that even that was enough in all cases, so add another call to CoFreeUnusedLibraries in the main RDM's finalization section. See the code snippet here:


procedure TMainRDM.BeforeDestruction;
begin
  fSharedDataRdm := nil;
  fChildRdm := nil;
  CoFreeUnusedLibraries;
  inherited;
end;

initialization
  TComponentFactory.Create(ComServer, TMainRDM,
    Class_MainRDM, ciMultiInstance, tmApartment);
finalization
  CoFreeUnusedLibraries;
end.

After doing this, I was not able to get the app server to hang in memory again.

Thursday, April 28, 2005 3:59:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
Delphi
Tracked by:
http://9nq-information.info/91666209/betta-life-expectancy.html [Pingback]
http://9ng-information.info/77423877/mariott-hotel-cebu.html [Pingback]
http://9nt-information.info/95642843/sky-management-albuquerque-nm.html [Pingback]
http://9nv-information.info/46728496/index.html [Pingback]
http://9nn-information.info/59542080/index.html [Pingback]
http://9ng-information.info/28165476/index.html [Pingback]
http://9nt-information.info/36778552/security-capital-european-realty.html [Pingback]
http://9no-information.info/75004567/index.html [Pingback]
http://9ns-information.info/85740632/sharon-white-jumping-horse.html [Pingback]
http://9ns-information.info/97905002/index.html [Pingback]
http://9ox-information.info/62823854/memorial-park-funeral-home.html [Pingback]
http://9oy-information.info/86999761/index.html [Pingback]
http://9ot-information.info/62553688/product-key-to-sim-city-3000-unlimited.html [Pingback]
http://9op-information.info/55508012/palm-backup-card-plus.html [Pingback]
http://9qh-information.info/28630955/cartina-friuli-venezia-giulia.html [Pingback]
http://9qg-information.info/37382436/index.html [Pingback]
http://9qb-information.info/44344505/index.html [Pingback]
http://9op-information.info/74221825/index.html [Pingback]
http://9rw-information.info/62541209/index.html [Pingback]
http://9sp-information.info/58818239/index.html [Pingback]
http://9ry-information.info/04955748/internet-explorer-add-on-errors.html [Pingback]
http://9rj-information.info/34721440/index.html [Pingback]
http://9rj-information.info/08798547/index.html [Pingback]
http://9uafr-le-informazioni.info/31452488/index.html [Pingback]
http://9uafe-le-informazioni.info/31134075/index.html [Pingback]
http://9uafi-le-informazioni.info/95286012/index.html [Pingback]
http://9uaeq-le-informazioni.info/66780668/cartolina-animate-buon-natale.html [Pingback]
http://9uaer-le-informazioni.info/68851215/www-luftansa.html [Pingback]
http://9uafd-le-informazioni.info/60572376/index.html [Pingback]
http://9uaeb-le-informazioni.info/42731402/index.html [Pingback]
http://9uaen-le-informazioni.info/38820333/index.html [Pingback]
http://9uagk-le-informazioni.info/90155723/bp-vi.html [Pingback]
http://9uahg-le-informazioni.info/26628788/index.html [Pingback]
http://9uahg-le-informazioni.info/85967248/il-pettirosso-siena.html [Pingback]
http://9uaga-le-informazioni.info/97869034/index.html [Pingback]
http://9uahb-le-informazioni.info/11684382/2006-fse.html [Pingback]
http://9uahg-le-informazioni.info/92105538/index.html [Pingback]
http://9uagj-le-informazioni.info/14658789/index.html [Pingback]
http://9uagr-le-informazioni.info/76143906/index.html [Pingback]
http://www.google.com/search?q=mebflrjw [Pingback]
Comments are closed.
Navigation
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Dan Miser
Sign In
Statistics
Total Posts: 339
This Year: 5
This Month: 0
This Week: 0
Comments: 618
All Content © 2010, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)