B4J Question Using JavaObject and releasing memory?

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

was looking for clipboard copy and paste functions without using an external library. The JavaObject offers such a possibility - see below.

Questions:
  1. Do JavaObjects remain in memory once there are created or are these released after functions like below have been used?
  2. If not the case, how to release JavaObjects?

B4X:
' CopyStringToClipboard via JavaObject
' Parameter: String
Sub CopyStringToClipboard(s As String)
    Dim ta As TextArea
    ta.Initialize("ta")
    ta.Text = s
    ta.SelectAll
    Dim jo As JavaObject = ta
    jo.RunMethod("copy", Null)
End Sub

' PasteStringFromClipboard via JavaObject
' Return: String
Sub PasteStringFromClipboard As String
    Dim ta As TextArea
    ta.Initialize("ta")
    Dim jo As JavaObject = ta
    jo.RunMethod("paste", Null)
    ta.SelectAll
    Return ta.Text
End Sub
 
Top