RTC Forums
November 24, 2024, 02:25:20 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
I'm not sure when I can free the components I have created
Pages: [
1
]
« previous
next »
Print
Author
Topic: I'm not sure when I can free the components I have created (Read 5109 times)
mthand
RTC Expired
Posts: 17
I'm not sure when I can free the components I have created
«
on:
September 17, 2015, 10:55:20 PM »
Delphi XE2, RTC v6.56 (2015.Q2)
I made a standalone unit to do a file download - no Form.
I create the TRtcHttpClient and a TRtcDataRequest, hook up the events, it all works great.
My problem is after the download completes, I don't know how or when to free those two components, so i have a memory leak.
I can't free them in the disconnect, and there is no FormClose where they could be freed.
Do you know how I could free them, either after a successful download, or if I detect a fail in the download ?
Logged
mthand
RTC Expired
Posts: 17
Re: I'm not sure when I can free the components I have created
«
Reply #1 on:
September 21, 2015, 01:58:29 PM »
Any thoughts on this ?
I have a RTCDataSet and an RTCHttpClient that I'm trying to free somehow after my download is finished..
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: I'm not sure when I can free the components I have created
«
Reply #2 on:
September 22, 2015, 10:48:49 PM »
Is your download fully event-driven and you want the components to be removed from memory after one of the RTC events, or are using WaitForCompletion to wait for the download to finish, after which you want to manually close the connection and release the components from memory?
Logged
mthand
RTC Expired
Posts: 17
Re: I'm not sure when I can free the components I have created
«
Reply #3 on:
September 22, 2015, 10:54:01 PM »
It's event driven. When the download is done, I want to free the RtcClient and the DataRequest.
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: I'm not sure when I can free the components I have created
«
Reply #4 on:
September 23, 2015, 02:08:08 PM »
1. Download the latest RTC SDK version. The absolute minimum version you will need is
v7.02
(just uploaded), because the "TRtcHttpClient" component was extended there with a new "BeforeDestroy" event, which you will need to implement (see point 3).
2. Use the "Release" method on the "TRtcHttpClient" component when you no longer need it (for example, when your download is finished). The "Release" method can be called from anywhere (even from inside events triggered by the component). After calling "Release", do NOT use the component anymore, as it could be destroyed at anytime from a background thread.
3. Implement the "BeforeDestroy" event on the "TRtcHttpClient" component to get notified when the component is about to be destroyed. Use that event to destroy all the other related components (for example, the "RtcDataRequest" component you have mentioned above). Because the "BeforeDestroy" could be called from a background thread (by the connection component provider thread which is destroying the connection component), do NOT try to access the GUI there.
PS. You can set the variable pointing to the "TRtcHttpClient" component to NIL immedaitely after calling "Release" or from the "BeforeDestroy" event, to avoid attempts to manually release the component from memory again (or use the component after releasing it).
Best Regards,
Danijel Tkalcec
Logged
mthand
RTC Expired
Posts: 17
Re: I'm not sure when I can free the components I have created
«
Reply #5 on:
September 28, 2015, 12:32:31 PM »
Thanks for the help with this. As of this moment I have not yet been able to install the newer version of RTC, I switched to using a form-based approach in order to get an unrelated fix to the field. I hope to get the new RTC going this week and will keep you informed. I appreciate your help.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...