Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:46:46+00:00 2026-05-31T07:46:46+00:00

Good day! Function GetService creates instance of class THTTPRIO and returns it as IInvokable.

  • 0

Good day! Function GetService creates instance of class THTTPRIO and returns it as IInvokable. I use this interface/object in another function. Do I have to free it or not when I don’t need it anymore? Interfaces does not need to be freed but I’m confused with the fact that RIO is created as object of THTTPRIO class.

function GetService(Addr: string): IInvokable;
var
  RIO: THTTPRIO;
begin
  RIO := THTTPRIO.Create(nil)
  RIO.URL := Addr;
  Result := (RIO as IInvokable);
end;

Where:

IInvokable = interface(IInterface);
THTTPRIO = class(TComponent, IInterface, IRIOAccess);

Thank you in advance! Vojtech

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:46:48+00:00Added an answer on May 31, 2026 at 7:46 am

    To answer the question you need to check how IInterface._AddRef and IInterface._Release are implemented for this class. They look like this:

    function TRIO._AddRef: Integer;
    begin
      Result := TInterlocked.Increment(FRefCount);
    end;
    
    function TRIO._Release: Integer;
    begin
      Result := TInterlocked.Decrement(FRefCount);
      if (Result = 0) and not (Owner is TComponent) then
        Destroy;
    end;
    

    This means that the lifetime of the object is managed by interface reference counting. Which means that your code is correct and does not leak.

    Note that if you had passed an Owner in the constructor then the lifetime would be managed by that owner instead.

    Your code is still somewhat liable to leaking if the setting of URL raises. I would write it like this:

    function GetService(const Addr: string): IInvokable;
    begin
      Result := THTTPRIO.Create(nil);
      (Result as IRIOAccess).RIO.URL := Addr;
    end;
    

    Having said all of that, the THTTPRIO class does not support IInvokable so perhaps your actual code looks slightly different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day! For this example of function html() http://api.jquery.com/html/ How to return to link
Good day! I want to create a function wherein I need to use JSON
Good day. I could really use your help on this one. I have a
Good day! I right now have a function the drags an element from a
Good day! I noticed that in anonymous event handler this is referenced to global
Good day guys, I've made a sweet favorites function with php mysql and ajax,
Good day! In his Effective STL Scott Meyers wrote A third is to use
Good day to all. I have this structure <html> <iframe> <div id=idd>Some Content</div> </iframe>
Good day to all. I have a problem with the following code: textBox.addEventListener(KeyboardEvent.KEY_DOWN,handler); function
Good day! I am trying to use jquery for the first time. And i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.