iOS Question Should a canvas always be released?

CaptKronos

Active Member
Licensed User
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:

B4X:
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?

B4X:
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.
 

CaptKronos

Active Member
Licensed User
Thanks. Can you explain why it is not possible to rely on a canvas being automatically released when it goes out of scope?
 
Top