-1

The problem I am facing is as follows.Please note I'm no pro at delphi pascal

To save a Large amount of memory and time I created a procedure:

procedure TForm1.Placeholder(tspath: STRING);
begin       //rgbholder :TImage globally declared (Dinamicly create image)
  rgbholder.Free;//Free previous image
  rgbholder := timage.Create(self);
  rgbholder.Width := 10;
  rgbholder.Height := 10;
  rgbholder.Visible := false;
  rgbholder.Bitmap.LoadFromFile(TSpath);
end;

procedure TForm1.Image3Click(Sender: TObject);
begin
  placeholder('Data\Grass\Grassanim1low.png');
  bitmaplistanimation5.Stop;
  bitmaplistanimation5.Loop := true;
  //bitmaplistanimation5.AnimationBitmap.LoadFromFile('Data\Grass\Grassanim1low.png'); 
  bitmaplistanimation5.AnimationBitmap.Assign( rgbholder.Bitmap);
  bitmaplistanimation5.AnimationCount := 22;
  bitmaplistanimation5.AnimationRowCount := 2;
  bitmaplistanimation5.Duration := 2.5;
  bitmaplistanimation5.PropertyName :='bitmap';
end;

Now my problem is freeing up that memory of the bitmaplistanimation5.AnimationBitmap.Assign(rgbholder.Bitmap);

When this code executes

bitmaplistanimation5.Stop;
bitmaplistanimation5.Enabled := false;
bitmaplistanimation5.AnimationBitmap.Free;

Everything goes well until I close the executable with a close; or by simply closing it with the exit in window.

After closing it throws a Application Error Exception EInvalidPointer in module Project1.exe at 00007A55. Invalid Pointer Operation

I don't think I'm trying to free memory that is already freed, I'm also not trying to free memory that was allocated somewhere other than the memory manager unless the placeholder procedure counts. Unless I'm missing something or not understanding something I should.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Note The Procedure Placeholder is used with multiple animations that requires the same file thus 3 ''animations of grass'' that uses the same memory it saves around 30-to 50 mb ram – Kira Yagami Jan 04 '17 at 14:05

1 Answers1

0

As a general rule, you should only call Free on an object that you created. You did not create this object, the TBitmapListAnimation control created it. So this code is a clear mistake on your part:

bitmaplistanimation5.AnimationBitmap.Free;

You will have to remove that.

I suspect that the right way to clear the memory from an FMX bitmap is to set the Width and Height properties of the bitmap to 0.

I wonder whether or not you really need to release this memory. If your program stops using the memory, and the system is short of memory, if can swap your unused memory to disk. It is common to find programmers who don't have a good understanding of virtual memory, taking actions like this that give no benefit. I would not be at all surprised if by trying to release this memory you actually made your program's performance worse rather than better.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Because this game is multi platform I will consider the virtual memory management for windows but I'm not sure how this will perform on android or even if it supports to this extent and that it would be efficient with slow sdcard memory and controllers.Also this application doesn't require real time memory loading when the Game is actually playing.I'm aiming for very low memory usage because of the amount of objects in game and very low hardware at 120 MB usable memory.The game menu uses around 85 Megabytes of Memory catching that would take 15-20 seconds where the gameplay uses around 110 MB – Kira Yagami Jan 05 '17 at 12:30