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

  • SEARCH
  • Home
  • 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 8330011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:59:01+00:00 2026-06-09T01:59:01+00:00

I’m fairly new to Delphi and have been doing all my memory management manually,

  • 0

I’m fairly new to Delphi and have been doing all my memory management manually, but have heard references to Delphi being able to use interfaces to do reference counting and providing some memory management that way. I want to get started with that, but have a few questions.

  1. Just generally, how do I use it. Create the interface and the class implementing it. Then anytime I need that object, have the variable actually be of the Interface type, but instantiate the object and presto? No nee to think about freeing it? No more try-finallys?

  2. It seems very cumbersome to create a bunch of interfaces for classes that really don’t need them. Any tips on auto generating those? How do I best organize that? Interface and class in the same file?

  3. What are common pitfalls that might cause me grief? Ex: Does casting the interfaced object to the an object of its class break my reference counting? Or are there any non-obvious ways Delphi would create reference loops? (meaning besides A uses B uses C uses A)

If there are tutorials that cover any of this, that would be great, but I didn’t come up with anything in my searches. Thanks.

  • 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-06-09T01:59:03+00:00Added an answer on June 9, 2026 at 1:59 am

    I am currently working with a very large project that takes advantage of the “side affect” of interface reference counting for the purpose of memory management.

    My own personal conclusion is that you end up with a lot of code that is overly complex for no better reason than, “I don’t have to worry about calling free”

    I would strongly advise against this course of action for some very basic reasons:

    1) You are using a side affect that exists for the purpose of COM compatibility.

    2) You are making your object footprint and efficiency heavier. Interfaces are pointers to lists of pointers.. or something along those lines.

    3) Like you stated… you now have to make piles of interfaces for the sole purpose of avoiding freeing memory yourself… this causes more trouble than it’s worth in my opinion.

    4) Most common bug that will be a HUGE pain to debug will become when an object gets freed, before it’s reference. We have special code in our own reference counting to try and test for this problem before software goes out the door.

    Now to answer your questions.

    1) Given TFoo and interface IFoo you can have a method like the following

    function GetFoo: IFoo;
    begin
      Result := (TFoo.Create as IFoo);
    end;
    

    …and presto, you don’t need the finally to free it.

    2) Yes like I said, you think it’s a great idea, but it turns into a huge pain in the bupkis

    3) 2 problems.

    A) you have Object1.Interface2 and Object2.Interface1… these objects will never be freed due to the circular reference

    B) Freeing the object before all the references are released, I cannot stress how dificult these bugs are to track down…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.