RobotStudio event

memory leak

Options

Hi all,

I have a major problem with my Flexpendant program (version 5.07)

My program has a timer_tick event of every 1 sec. Every 1 sec it is calling a subroutine that makes connection with the controller, get/write some data, dispose it etc. I've also read the disposing on the user forum and i dispose the rapid data before the controller.

My problem is that every minute the memory of the FP is dropping about 100KB. The available memory is about 23MB, so after a while the FP restarts itself. There's no memory leaking problem message showing. The code is as follows.


Dim AController As Controller 'connect with robot controller
Dim ARapid As Rapid 'connect with rapiddata
Dim rbt_rdPickpoint As RapidData ' Temp data
Dim rbt_rdtPickpoint As RapidDataType ' Temp data Type
Dim rbt_udPickpoint(1) As UserDefined ' Userdefined structure

 


Dim rbt_rdPattern As RapidData ' Temp data
Dim rbt_rdtPattern As RapidDataType ' Temp data Type
Dim rbt_udPattern(1) As UserDefined ' Userdefined structure
AController =
New Controller ' assign new class controller
ARapid = AController.Rapid
' assign new class rapid data
' -- read data,
rbt_rdPickpoint = ARapid.GetRapidData("MAINTASK", "GLOBAL", "Pickpoint")
' Get data
rbt_rdtPickpoint = ARapid.GetRapidDataType("MAINTASK", "GLOBAL", "tPickpoint")
' Get data structure
rbt_Pickpoint(1) =
New tPickpoint(rbt_rdtPickpoint) 'define new tmp structure, 1ste pp
rbt_Pickpoint(1).FillFromString((
DirectCast(rbt_rdPickpoint.ReadItem(1), UserDefined)).ToString()) ' set data in the right var
rbt_udPickpoint(1) =
DirectCast(rbt_rdPickpoint.ReadItem(1), UserDefined)
rbt_rdPattern = ARapid.GetRapidData("MAINTASK", "GLOBAL", "Pattern")
' Get data
rbt_rdtPattern = ARapid.GetRapidDataType("MAINTASK", "GLOBAL", "tPattern")
' Get data structure
rbt_Pattern(1) =
New tPattern(rbt_rdtPattern) 'define new tmp structure
rbt_udPattern(1) =
DirectCast(rbt_rdPattern.ReadItem(1), UserDefined)
rbt_Pattern(1).FillFromString((
DirectCast(rbt_rdPattern.ReadItem(1), UserDefined)).ToString()) ' set data in the right var
' Pickpoint
If Not rbt_rdPickpoint Is Nothing Then
rbt_rdPickpoint.Dispose()
rbt_rdPickpoint =
Nothing
End If
If Not rbt_rdtPickpoint Is Nothing Then
rbt_rdtPickpoint.Dispose()
rbt_rdtPickpoint =
Nothing
End If
' Pattern
If Not rbt_rdPattern Is Nothing Then
rbt_rdPattern.Dispose()
rbt_rdPattern =
Nothing
End If
If Not rbt_rdtPattern Is Nothing Then
rbt_rdtPattern.Dispose()
rbt_rdtPattern =
Nothing
End If
If Not ARapid Is Nothing Then
ARapid.Dispose()
ARapid =
Nothing
End If
' dispose variables
If Not AController Is Nothing Then
AController.Dispose()
AController =
Nothing
End If

Is there something wrong with my code or with RAB5.07. Can anyone help me?

Comments

  • RussD
    Options

    I'm not sure why your application is leaking memory as you describe, how much memory does it consume before it restarts?I've never used UserDefined structure; you might try disabling that part of your code to see if there is a problem with that particular item.
    Addditionally, you might try some of the following changes to see if they improve the behavior of your application:
    1. Create a controller reference when your app is instantiated and use that same reference throughout its lifecycle, instead of creating and destroying it in each tick event.
    2. Create "variable subscriptions" to the the data you need to read when your app is instantiated and add event handlers for the ValueChanged events for each value. This will simplify or maybe eliminate the need for the the timer, which itself can be quite burdensome to the platform. You can then dispose these resources at the end of the app lifecycle.
    For instance, you might try do something like:
    'initialization code
    'assumes a controller reference, "ctrl", is already created
    Dim RapidDataSub as RapidDomain.RapidData
    RapidDataSub = ctrl.Rapid.GetRapidData("myNumVar")
    AddHandler RapidDataSub.ValueChanged, AddressOf InvokeRapidDataSubChanged
    'now when the value changes, the event handler will be called

    Private Sub
    InvokeRapidDataSubChanged(ByVal sender As Object, ByVal e As RapidDomain.DataValueChangedEventArgs)
    'this code is not executing on the main thread, so we must invoke it back to the main thread if
    'we need to use it to update the UI
    Me.Invoke(New EventHandler(AddressOf UpdateUI), sender, e)
    End Sub
    Private Sub UpdateUI(ByVal sender As Object, ByVal e As System.EventArgs)
    'do something useful with the fact that the value changed; the MessageBox
    'here is simply used to demonstrate the principle
    GTPUMessageBox.Show(Me, Nothing, _
    "The variable value changed.", _
    "Value Changed!", _
    System.Windows.Forms.MessageBoxIcon.Hand, _
    System.Windows.Forms.MessageBoxButtons.OK)
    End Sub
    Russell Drown
  • Huyle
    Options

    Hi Russ,

    Thank you for your help. I try to relocate the controller reference after the program is initialized, but that doesn't help. You have to move the rapid reference also.  I also implement the second option, as an event, but i have seen that if the data change every 2 s, the event handler cannot follow the changement. Therefore it is showing a queue error for that event after a while, so i think i still have to use the timer tick to update my UI.

    i have another question. I have seen, if you open and close a screen on the flexpendant, it doens't matter what kind of screen (for eg, the IO, Jogging) is use some memory. It you do this a lot it lose a lot a memory. When will the use memory be available again, even if the program is close?

    Regards,

    Huynh

  • RussD
    Options

    It is my understanding that launching the ABB menu is supposed to force the garbage collector to run, which should reclaim unreferenced memory.

     

    Russell Drown