Menu

#238 DPFUIImageView Memory Leak

fixed
Bug
2014-03-16
2014-03-10
Diego
No

Hi Babak:

Long time without talking!

I think I have found a memory problem with TDPFUIImageView.

Each time you assign a new bitmap to it, the RAM memory is decreased and it is never released, even if you do a DisposeOf().

So, eventually, you get a crash (tested in real devices) with the out of memory error.

I prepared a sample where you can see it.

It has 3 forms, the main is a selector with the Firemonkey and the DPF options. With the firemonkey component TImage you can assign a new bitmap anytime, however, with DPF the memory leak appears with 15-20 assignments.

Greetings!

Just press the "Fill Chart" button in both forms (the firemonkey and the dpf one) and you can see it by yourself.

1 Attachments

Discussion

  • Babak Yaghoobi

    Babak Yaghoobi - 2014-03-14

    Hi Diego

    How did you compile this example with TChart on iOS !?
    So that I know the iOS not have a chart component.

    Please tell me more about it.

    Regards

     
  • Diego

    Diego - 2014-03-14

    Hi Babak, they are the Steema Charting components included in Firemonkey plattform for XE4 and XE5. I don´t know if they are included in all RAD Studio versions.

    Since they are not native... I managed to capture their frame with Makescreenshot and then load the image into a native UIImage. (The posted source shows how to do this)

    I tried to load the images in several ways (with SetImage, Bitmap directly, etc)...

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-03-14

    Hi Diego

    Can you reproduce this bug with another sample without chart ?

    Thanks.

    Regards

     
  • Diego

    Diego - 2014-03-14

    Sure Babak.

    I have removed the chart.

    The bigger and complex the bitmap is, the sooner it will crash the application.
    With this sample in an iPad 2 takes about 35-40 taps to crash. If you have a device with more RAM, it will take longer.

    In simulator it doesn´t crash (I guess it is because it has much more RAM than a real device)

    You can use instruments to check how fast the RAM is decreased with TDPFUIImageView bitmat assignment, while with Firemonkey TImage it works OK.

    If you have cydia installed, I recommend you to install the free tool: StatusModifier, which allows you to see the free ram in status bar. This way you can see it directly in your device.

    Thanks for your support!

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-03-15

    Hi Diego

    Fixed.
    Please download last source [code]
    Thank you for your feedback.

    Regards

     

    Related

    Code: code

  • Babak Yaghoobi

    Babak Yaghoobi - 2014-03-15
    • status: open --> fixed
     
  • Diego

    Diego - 2014-03-15

    Hi Babak:

    Thanks for the help!

    Anyways, it seems there is still a problem when you do a "DisposeOf" in a TDPFUIImageView.

    I have prepared the same demo, but this time, the TDPFImageView is created and destroyed in runtime.

    With this situation, the memory leak appears again. Maybe I am not freeing the component correctly...

    I tried to clearimage before destroying it, but it didn´t help.

    Thanks in advance!

     
  • Diego

    Diego - 2014-03-16

    Hi again Babak:

    I think I have found the solution.

    As you already did in the procedure DoBitmapChanged, I added the line

    if FUIImageView.image <> nil then FUIImageView.image.release;
    

    to the destructor TDPFImageView.Destroy

    like this:

    destructor TDPFImageView.Destroy;
    begin
      if FUIImageView.image <> nil then FUIImageView.image.release;
      FBitmap.DisposeOf;
      FImageList.DisposeOf;
    .
    .
    .
    

    There is still a small memory leak if you create a lot of images (12 or so) with big bitmaps assigned to them. Anyways, I think it won´t be a problem and I'll try to find the solution on my own.

    Thanks again Babak!

     

    Last edit: Diego 2014-03-16
  • Babak Yaghoobi

    Babak Yaghoobi - 2014-03-16

    Hi Diego

    Don't add this line inside Destroy section, this work for you only if you set BitMap image in others this cause crash your app!

    I changed some codes for fix leak,
    Download last source code and test it again please.

    Regards

     
  • Diego

    Diego - 2014-03-16

    Hi Babak:

    It is working perfectly.

    Thanks a lot!

    By the way, you forgot the {IFDEF IOS} in var declaration of DoBitmapChanged.

    Greetings!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.