Although setting TImage::Picture = NULL won't cause a memory leak, what alternatives exist that might avoid that confusion?

Pete

Despite bummi's fine explanation of why Image1.Picture := nil won't cause a memory leak, I'm concerned that it may raise red-flags in the minds of new people reading my code, since its safety is counter-intuitive. Therefore, I'd like to avoid it. What more-intuitive alternatives exist? Although bummi's answer was for Delphi, I'm actually more interested in C++Builder.

Pete

Encapsulating the property assignment provides two advantages:

  1. a single location to document the non-leakiness of it (DRY)
  2. a less worrisome-looking interface to use everywhere else

e.g.:

// Not a memory leak: see http://stackoverflow.com/a/23999207/782738
#define ClearImage(Image) Image->Picture = NULL

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is setting ulimit -v sufficient to avoid memory leak

From Dev

What is the cause of this strange Scala memory leak?

From Dev

Setting allowdrop to true cause memory leak in .net application

From Dev

angular.js: using events to trigger actions in controllers might cause memory leak

From Dev

What might cause a Null Reference Exception when creating an empty list?

From Dev

What might be alternatives to Userena in Django?

From Dev

Avoid Memory leak

From Dev

How to avoid this memory leak?

From Dev

Does Func<T> callbacks can cause memory leak?

From Dev

will ifstream cause memory leak if I don't close?

From Dev

What might be the cause of this error in JSON?

From Dev

What might be the cause of this error in JSON?

From Dev

Does clearing an image by assigning Image1.Picture := nil; cause a memory leak?

From Dev

Fragment view memory leak despite setting parent view to null in onDestroyView

From Dev

Will this cause a memory leak in c++?

From Java

Is it possible to cause a memory leak in Rust?

From Dev

Finding the cause of a memory leak in Ruby

From Dev

will this cause a memory leak in C#

From Dev

Will below code cause memory leak?

From Dev

Will this cause a memory leak in c++?

From Dev

Will emptying an Array = [ ] cause memory leak?

From Dev

Does this Bitmap cause a memory leak?

From Dev

React Memory Leak Although i return a clearinterval?

From Dev

Avoid memory leak with WeakReference Android

From Dev

what might cause the last value in .push to be dropped?

From Dev

How to release memory in android to avoid memory leak

From Dev

Not enough memory, setting a picture in a userform

From Java

Does never resolved promise cause memory leak?

From Dev

Will this method cause a memory leak when it throws an exception?

Related Related

  1. 1

    Is setting ulimit -v sufficient to avoid memory leak

  2. 2

    What is the cause of this strange Scala memory leak?

  3. 3

    Setting allowdrop to true cause memory leak in .net application

  4. 4

    angular.js: using events to trigger actions in controllers might cause memory leak

  5. 5

    What might cause a Null Reference Exception when creating an empty list?

  6. 6

    What might be alternatives to Userena in Django?

  7. 7

    Avoid Memory leak

  8. 8

    How to avoid this memory leak?

  9. 9

    Does Func<T> callbacks can cause memory leak?

  10. 10

    will ifstream cause memory leak if I don't close?

  11. 11

    What might be the cause of this error in JSON?

  12. 12

    What might be the cause of this error in JSON?

  13. 13

    Does clearing an image by assigning Image1.Picture := nil; cause a memory leak?

  14. 14

    Fragment view memory leak despite setting parent view to null in onDestroyView

  15. 15

    Will this cause a memory leak in c++?

  16. 16

    Is it possible to cause a memory leak in Rust?

  17. 17

    Finding the cause of a memory leak in Ruby

  18. 18

    will this cause a memory leak in C#

  19. 19

    Will below code cause memory leak?

  20. 20

    Will this cause a memory leak in c++?

  21. 21

    Will emptying an Array = [ ] cause memory leak?

  22. 22

    Does this Bitmap cause a memory leak?

  23. 23

    React Memory Leak Although i return a clearinterval?

  24. 24

    Avoid memory leak with WeakReference Android

  25. 25

    what might cause the last value in .push to be dropped?

  26. 26

    How to release memory in android to avoid memory leak

  27. 27

    Not enough memory, setting a picture in a userform

  28. 28

    Does never resolved promise cause memory leak?

  29. 29

    Will this method cause a memory leak when it throws an exception?

HotTag

Archive