C CaptKronos Active Member Licensed User Longtime User Feb 13, 2019 #1 From reading the forum I understand that after using a canvas it should be released. However, I am not sure if that is always the case or whether I can rely on iOS clearing up for me (i.e. relying on ARC). For example: Code: Sub doSomethingWithACanvas Dim c As Canvas Dim iv As ImageView iv.Initialize("") . . . c.Release End Sub Is that final c.release required? If it is, how would I handle the following example where I need to keep the canvas in order to be able to return the bitmap? Code: Sub doSomethingWithACanvas as bitmap Dim c As Canvas Dim iv As ImageView iv.Initialize("") . . . Return c.CreateBitmap End Sub I assume I can't release the canvas before the c.CreateBitmap statement? Also, are there any other structures that have to be treated in this way, e.g bitmaps? Thanks.
From reading the forum I understand that after using a canvas it should be released. However, I am not sure if that is always the case or whether I can rely on iOS clearing up for me (i.e. relying on ARC). For example: Code: Sub doSomethingWithACanvas Dim c As Canvas Dim iv As ImageView iv.Initialize("") . . . c.Release End Sub Is that final c.release required? If it is, how would I handle the following example where I need to keep the canvas in order to be able to return the bitmap? Code: Sub doSomethingWithACanvas as bitmap Dim c As Canvas Dim iv As ImageView iv.Initialize("") . . . Return c.CreateBitmap End Sub I assume I can't release the canvas before the c.CreateBitmap statement? Also, are there any other structures that have to be treated in this way, e.g bitmaps? Thanks.
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2019 #2 You always need to call Canvas.Release when you are done using the canvas. In many cases it is better to create the canvas one and reuse it. Code: Dim bmp As Bi4map = c.CreateBitmap c.Release Return bmp End Sub Upvote 0
You always need to call Canvas.Release when you are done using the canvas. In many cases it is better to create the canvas one and reuse it. Code: Dim bmp As Bi4map = c.CreateBitmap c.Release Return bmp End Sub
C CaptKronos Active Member Licensed User Longtime User Feb 14, 2019 #3 Thanks. Can you explain why it is not possible to rely on a canvas being automatically released when it goes out of scope? Upvote 0
Thanks. Can you explain why it is not possible to rely on a canvas being automatically released when it goes out of scope?
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2019 #4 The Canvas is based on a native resource that must be explicitly released. It might have been possible to rely on its internal dispose method. The way it was implemented you must call Release. Upvote 0
The Canvas is based on a native resource that must be explicitly released. It might have been possible to rely on its internal dispose method. The way it was implemented you must call Release.
C CaptKronos Active Member Licensed User Longtime User Feb 14, 2019 #5 That's clear. Thanks again. Upvote 0