RTC Forums
April 19, 2024, 12:49:06 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: How to destroy linked objects?  (Read 7938 times)
Dany
RTC License++
*****
Posts: 69


« on: August 10, 2018, 12:49:47 PM »

I have a DataModule that is created on the server using an TRtcLinkedModule component. No automatic object creation is performed on the client. When the client wants to dispose of the (client side) object, i found i can call RtcCLientModule.RemoveManagedObjects; and that will destroy the linked object that this client created. Super!

But i still have a problem when that do not happen for some reason. When i terminate my server application, the DACs finalization section is run before the auto-created server-side objects are destroyed so the DAC do not have the DB dll loaded anymore... Boom!

I am trying to find a way to destroy the objects when the server has to be "forcefully" terminated, but to no avail. Can you help?

TIA,

/Dany
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: August 10, 2018, 01:04:08 PM »

What do you mean by "DAC"?
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #2 on: August 10, 2018, 01:06:28 PM »

DAC = Data Access Components. Sorry.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: August 10, 2018, 01:11:49 PM »

Where is the TDataModule (containing the TRtcLinkedModule) created on the Server and where is it being destroyed? Making sure that the TDataModule is destroyed (after stopping the Server Listener) before the application starts terminating (and finalization sections start executing) should eliminate the problem.
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #4 on: August 10, 2018, 01:22:10 PM »

I have registered a constructor (or rather several) in a ServerModule containing a TRtcHttpServer and a TRtcServerModule. The TRtcHttpServer has it's ObjectLinks set to ol_AutoClient. The constructor is executed properly. It constructs another DataModule that contains the TRtcLinkedModule component.
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #5 on: August 10, 2018, 01:30:04 PM »

What i mean is that since RTC can destroy (and will) these objects when everyting is ok, then if i keep a list of my own and traverse that when stopping to listen i'll free modules that RTC have destroyed already. Should i create an owner that asks my modules to notify it upon destruction? Isn't there a call i can do to get "dangling" objects destroyed?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #6 on: August 10, 2018, 01:34:18 PM »

Automatically created Modules are stored inside Sessions, but Sessions aren't destroyed when the Server is stopped, so these Modules will remain in memory until the "rtcDataSrv" units finalization section completes (where "DoneSessions" is called). But this shouldn't be a problem if a Server has already stopped listening and there are no Clients executing code on the Server. So ... what exactly does go BOOM?
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #7 on: August 10, 2018, 01:46:11 PM »

After successfully calling ListenStop when i terminate the server application.

Here is the callstack when i terminate the server application:

Code:
:7441ddc2 KERNELBASE.RaiseException + 0x62
IB_Session.TIB_SessionBase.isc_rollback_transaction($BB5,$19FB11)
System._Assert('Assertion failure','C:\Users\Superkey\Documents\SleekProductions\3rdParty\IBO\source\core\IB_Session.pas',2997)
IB_Session.TIB_SessionBase.isc_rollback_transaction($19FB50,$4D0C2FC)
IB_Components.TIB_Transaction.API_Rollback
IB_Components.TIB_Transaction.SysRollbackBegin(False)
IB_Components.TIB_Transaction.SysRollback(False)
IB_Components.CloseWithLosses
IB_Components.TIB_Transaction.Close
IB_Components.TIB_Connection.CloseTransactions
IB_Components.TIB_Connection.Destroy
System.TObject.Free
System.Classes.TComponent.DestroyComponents
System.Classes.TComponent.Destroy
System.Classes.TDataModule.Destroy
System.TObject.Free
rtcInfo.TRtcObjectLink.DestroyOwner
rtcInfo.TRtcObjectManager.FreeObjects
rtcInfo.TRtcObjectManager.Destroy
rtcLink.TRtcRemoteObjectManager.Destroy
System.TObject.Free
rtcTypes.RtcFreeAndNil((no value))
rtcInfo.TRtcInfo.Clear
rtcInfo.TRtcRecord.Destroy
rtcInfo.TRtcSession.Destroy
System.TObject.Free
rtcTypes.RtcFreeAndNil((no value))
rtcDataSrv.DoneSessions
rtcDataSrv.TRtcDataSrvUnit.Destroy
System.TObject.Free
rtcTypes.RtcFreeAndNil((no value))
rtcDataSrv.Finalization
System.FinalizeUnits
System._Halt0

This happen so late that the finalization section of the DACs session unit has been executed. So it's client library has been closed.

Maybe i'm doing something wrong with the sessions. I have not added any session-specific code yet, though.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #8 on: August 10, 2018, 01:55:21 PM »

Are you calling ListenStop, or ListenStopNow?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #9 on: August 10, 2018, 02:00:07 PM »

If your Database components finalization section is being called before RTC components finalization sections, maybe changing that would fix the problem? You should be able to achieve that by adding your Database components units somewhere at the top of your Projects uses list, most importantly above any RTC units or units using RTC units.
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #10 on: August 10, 2018, 02:06:10 PM »

Tried both, will change to ListenStopNow and see what happens.

Yes, i was thinking about the order of finalization. I'll try that too, but since the IDE (and even other 3rd party stuff) sometimes changes the uses sections that feels a bit "shaky".

I have two thing to try no, i'll keep you posted.

Thanks,

/D
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #11 on: August 10, 2018, 03:15:00 PM »

I am not an expert on units and linking, but after sorting all the uses clauses i put the DAC's unit containing the finalization section firs in the projects dpr-file. This is fine because i can comment and maintain this in a reliable fashion.

Thank you again!

/D
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.026 seconds with 16 queries.