Author Topic: Terrible memory leak in REALbasic 5.5.5  (Read 365 times)

Offline Knezzen

  • Platinum Member
  • *****
  • Posts: 764
  • Pro Tools addict!
    • Macintosh Garden
Terrible memory leak in REALbasic 5.5.5
« on: October 20, 2018, 01:58:47 PM »
Hi!

Just finished backporting MacTorrent to REALbasic 5.5.5 just to be able to develop the application in Mac OS 9 and not just use it there.

Now to the problem. The back ported code leaks terribly when ran (after the application is built etc).
It uses up as much memory as the torrent data that is written to disk is big, so the problem lays somewhere in the part of the code that manages the torrent data (I think).
The frustrating part is that the code runs well without memory leaks in REALbasic 2005 and newer (without rewriting anything), so it's really hard to find where the memory leak comes from. REALbasic 2005 and newer probably uses some other kind of garbage collecting that is more effective. Something that RB 5.5.5 doesn't do.

Would be wonderful if some REALbasic guru could lend me a helping hand on the matter. I want to get new versions of MacTorrent out the door so to say, and I want to do that using RB 5.5.5.

So... Help! :)

Offline OS923

  • Gold Member
  • *****
  • Posts: 319
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #1 on: October 31, 2018, 02:27:43 AM »
In REALbasic 5.5.5 a socket can continue to exist even when the connection is closed and all references to the socket are gone. (The garbage collection is implemented as reference counted pointers, so as soon as there are no references to your object anymore, it's automatically deleted, except for sockets.) See the documentation about sockets. This is the only way that it can cause memory leaks.

Offline Knezzen

  • Platinum Member
  • *****
  • Posts: 764
  • Pro Tools addict!
    • Macintosh Garden
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #2 on: October 31, 2018, 05:28:29 AM »
Thank you very much for your input! Will look into this tonight.

Offline OS923

  • Gold Member
  • *****
  • Posts: 319
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #3 on: November 09, 2018, 09:36:16 AM »
There's also a way in which YOU can cause a memory leak, but since your program used to work normally in REALbasic 2005, this probably didn't happen in REALbasic 5.5.5.

Code: [Select]
App.Open:
Sub Open()
  dim a as Thing
  dim b as Thing
  dim c as Thing
 
  a=new Thing
  b=new Thing
  c=new Thing
 
  a.m_next=b
  b.m_next=a
  c.m_next=c
End Sub

App.Close:
Sub Close()
  #if DebugBuild then
    DebugDumpObjects("Objects.txt")
  #endif
End Sub

Offline OS923

  • Gold Member
  • *****
  • Posts: 319
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #4 on: November 09, 2018, 09:36:59 AM »
There are also so-called memory leaks that can resolve themselves:

Code: [Select]
App.Open:
Sub Open()
  dim a as TimerThing
 
  a=new TimerThing
  a.m_next=a
  a.mode=2
  a.period=1000
  a.enabled=true
End Sub

App.Close:
Sub Close()
  #if DebugBuild then
    DebugDumpObjects("Objects.txt")
  #endif
End Sub

TimerThing.Destructor:
Sub Destructor()
  m_next=nil // place here breakpoint.
End Sub

TimerThing.Action:
Sub Action()
  m_seconds=m_seconds+1
  if m_seconds=10 then
    m_next=nil
  end
End Sub

Offline Naiw

  • Consistant Contributor
  • ***
  • Posts: 96
  • new to the forums
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #5 on: November 15, 2018, 11:48:23 AM »
There's also a way in which YOU can cause a memory leak, but since your program used to work normally in REALbasic 2005, this probably didn't happen in REALbasic 5.5.5.

Code: [Select]
App.Open:
Sub Open()
  dim a as Thing
  dim b as Thing
  dim c as Thing
 
  a=new Thing
  b=new Thing
  c=new Thing
 
  a.m_next=b
  b.m_next=a
  c.m_next=c
End Sub

App.Close:
Sub Close()
  #if DebugBuild then
    DebugDumpObjects("Objects.txt")
  #endif
End Sub

Ie the kind of memory leaks you expect from reference counting.

Offline OS923

  • Gold Member
  • *****
  • Posts: 319
Re: Terrible memory leak in REALbasic 5.5.5
« Reply #6 on: November 16, 2018, 08:01:02 AM »
Did you try DebugDumpObjects? It should tell you the name of the class of the lost objects. Then you have an idea where to search.

You can also try to make a class dependency graph. This should be a directed graph. If  you have circular references then you should find a loop in the graph.