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 7218951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:33:18+00:00 2026-05-28T21:33:18+00:00

I have a callback procedure: type TInitCallback = procedure (var Data: Pointer); The idea

  • 0

I have a callback procedure:

type
  TInitCallback = procedure (var Data: Pointer);

The idea is that after initialization Data could point to anything.

I’ve tried to assign this procedure to the callback and init Data in a way that it should point to a newly created array:

type
  TBoolArray = array of Boolean;

procedure InitData(var Data: Pointer);
var
  BoolArray: TBoolArray;
  i: Integer;
begin
  SetLength(BoolArray, 10);
  for i := 0 to Length(BoolArray) - 1 do
    BoolArray[i] := False;
  Data := BoolArray;
end;

However, I am not sure that reference counter is increased for array when assigning: Data := BoolArray;. In other words – I am not sure that array is still in memory after leaving the procedure or has it been freed?

Because later in a program execution, when I change the data in some other structure ( a record which has nothing to do with this array), this change makes changes in earlier allocated array(Data).

One explanation for this would be that the memory for array was freed when leaving the callback and reused once again for the record.

So, does the array stays allocated after leaveing InitData callback or not? And if not, how to make it stay allocated. Please not that I do not want to change the signature of my callback, I can not introduce any new params or change it to a function.

Thank you.

  • 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-28T21:33:19+00:00Added an answer on May 28, 2026 at 9:33 pm

    You are correct in your assumption that the reference count of the dynamic array is not incremented when you assign to Data. This means that the local array goes out of scope when InitData returns. Thus your code is broken.

    The most simple solution would be to change the definition of TInitCallback to use a dynamic array and then the reference mechanism would manage the lifetime for you. Since you do not wish to change your interface then you have (at least) the following options:

    1. Make BoolArray a global variable. That would only work if there is only one instance in your application.
    2. Change the type of BoolArray to ^TBoolArray and use New to allocate this on the heap. You would also need to add another procedure which would deallocate the array with a call to Dispose.
    3. Very similary to option 2, wrap the array in a class. Class instances can be safely stored in pointers. Again you would need another function to dispose of the class instance by calling Free.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I have a set of callback classes that I use for handling callbacks with
I have a list of callback functions that I need to invoke when an
I have a webservice that when called without specifying a callback will return a
I have a member function in a class that has a callback, but the
I have a stored procedure that returns a varchar(160) as an output parameter of
I have a callback that is called through a delegate. Inside it I will
I have a callback method that I got to work, but I want to
I know that .append() does not have any callback function, but when I try
I have a callback from an ajax call that returns a bunch of image

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.