Jump to content
Sign in to follow this  
KMarb

Android / FMX - To Free or Not To Free (or FreeAndNil)

Recommended Posts

Delphi 11.1, creating android apps

 

In researching other topics I found some discussion that android is a different beast in terms of memory management, and maybe we should no longer call free or freeAndNil?

 

I haven't had an issue until now... The following code blows up:

  freeAndNil (SyncCDS);
  freeAndNil (SyncQuery);
 

When earlier in the execution, I called this code:

 

  SyncQuery := TFDQuery.Create (nil);
  SyncQuery.Connection := DMConn.dbcMain;

  SyncCDS := TClientDataSet.Create (nil);

 

Not sure it matters but this code is running in a TTask.Run procedure.

 

Can someone please explain the (new) mindset around allocating and freeing objects in android please.

 

Share this post


Link to post
10 minutes ago, KMarb said:

Delphi 11.1, creating android apps

 

In researching other topics I found some discussion that android is a different beast in terms of memory management, and maybe we should no longer call free or freeAndNil?

This was correct until Delphi 10.4 when ARC ( Automatic Reference Counting) was removed. Now you code the same way on all of the platforms and have to call free or if you must call freeAndNil (freeAndNil is in 99.999999999999999999% a code smell.)

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×