None reponsive program

In the evolution of my home automation rewrite I was finally able to test overnight it’s operation live. Unfortunately, the program will go none responsive after a period of hours. My guess is I may be declaring instances that are permanent by holding their declaration in a properties module. For instance, I have declared SC as a serialController with an assortment of methods which is a sub of serial. I’m thinking that I may be keeping each instance alive in the repeated sequence of operations and choking the program. Should I do a SC.Close after calling each subroutine module? Could this be so or should I look for other reasons? I’m a little vague about how this works.

Xojo has a Runtime object ( You can count the open objects. I seem to remember some classes that made tracking easier. This one here? Releases · kmaehashi/XojoInstruments · GitHub

Add some logging to your app to see if you kill everything that you create. currentMethodName is the most helpful function there.

Good start Beatrix. I notice the number of processes stabilized at 249 but the memory used increases about 5000 on each pass. How do I set up logging and what would I look for?

Why is the number of processes so high? Is this normal for you app?

For my log files I write data to a file in ApplicationSupport:

dim theBinStream as BinaryStream

'make new file or open existing one
if not theLog.Exists then
theBinStream = BinaryStream.Create(theLog)
theBinStream = BinaryStream.Open(theLog, True)
end if
if theBinStream = Nil then Return

'size limit was reached
if theBinStream.Length > SizeLimit then
theBinStream = Nil
theLog = CreateLog
theBinStream = BinaryStream.Create(theLog)
end if
if theBinStream = Nil then Return

'write the data
theBinStream.BytePosition = theBinStream.Length
theBinStream.write GetDateTime + " " + Indent + LogText + theLine

catch IOExc as IOException
end try

I roughly log what the app is doing with

globals.theErrorLog.LogItem CurrentMethodName
'method code here
Globals.theErrorLog.LogItem CurrentMethodName + " done"

You can use something similar to check if your classes or your processes are killed or not.

I’m not sure what normal number of processes might be but this home automation software is what I believe might be extensive. I do notice the list includes many items that appear to be GUI items.

I can tell you are very knowledgeable in this field and it might take a lot of patients to get me through setting this logging process up. I would understand if you have better things to do but I would be grateful if you could further help me.
I copied the code to a method in my main window and I see this right off:

MainWindow.logFile, line 4
This item does not exist
If Not theLog.Exists Then

I thought it would be created but apparently not. So I need to?

When you say ApplicationSupport, do you mean in my user library?

I was able to download a demo logging program from Mike Cotrone and it seems to work. I’m not sure yet how to incorporate it into my program but I will figure it out. Where do the messages that you wish to capture come from?

Is this on Mac OS?
Be aware that, on Mac OS, there’s a process count limit (and it’s near, just below, 256, IIRC). If you happen to reach this limit, you won’t be able to launch any more apps/processes, by any means.
Finder, Dock, and all API calls to open another process would return error -10810 (LSUnknownError, like if this limit was set without being known by the rest of the OS…). Xojo wouldn’t launch a debugged app, with the same unknown code.
If Terminal is already open and you open a new window, it will tell “Resource busy” in the window and terminate, not letting you writing anything.
I “enjoyed” this state, 10 years ago. Everything was so odd, as not really handled by the OS. It took some times to even understand that a process limit existed and was the culprit.
Those are the times where one learns a lot about the OS.

I uploaded my log handler class to

From the note:

Adding log handler to your project:
Add the folder “log handler f” to your project.
Create a new log handler with
Globals.theErrorLog = new ErrorLogHandler(true)

You can now use the log handler with code like this:

Globals.theErrorLog.logitem currentMethodName, “open”
dim f as FolderItem = getopenfolderitem("")
Globals.theErrorLog.logitem currentMethodName + " done", “close”

The result is in the Application Support folder under the name of the application. The project here results in a folder called “test.debug”.

As always my code is for use on macOS. Tested with Xojo 2019r3 and 2020r1. MBS plugin is used for getting some information about the computer,
getting memory information, fonts and the version of macOS.

log handler can log memory information for checking a memory leak. It can also do different sort of messagesboxes which can run in a thread.
The messageboxes are logged into the session log.

That’s very kind of you, Beatrix. Your example and class will be helpful. I will work on implementing it.

Yesterday I removed a thread that I thought was working well but may have been causing the issue. The software ran all night without hanging. The thread was being used to perform all my serial I/O business to the interface controller. Its responsibility was to read all temperature and digital input. Without it, I was always fighting the beach ball during these operations. I’m not sure why the thread causes a random unpredictable hang. I even halted other processes during its data collection operation to ensure no I/O conflicts. It still was handy making it easy to open other preference windows without the beach ball.
When the thread was to run the program sequencer, which controls many other operations would set its own sequencer timer to off. After the thread ran the timer would be set to single again and the process would repeat.

Any thoughts why a thread might cause an issue like this?

npalardy@server ~ % ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       5568
-n: file descriptors                256
npalardy@server ~ % 

Yes, Arnaud, it’s on Mac OS. It sounds like a steep learning curve as it is for me now.

After looking at the process list I wonder what constitutes a process and can some be stopped? I notice many are labels, textfields, arrays, VarientStrings, Date, DateTime, Menuitem. Are these actually considered processes?

As I mentions to Beatrix, it seems my problem is associated to using a thread. If you have thoughts on that post, please share.

process is roughly an application

Please look at my last post to Arnaud.

No they can’t be stopped or no these are not processes?

updated my reply to make it clearer
labels and such are NOT processes
If you’re seeing these in the debugger you’re looking at instances and variable in a single process - the application you’re debugging

What might I need to change in this code to see processes:

Var lastObjectIndex As Integer = Runtime.ObjectCount - 1
For i As Integer = 0 To lastObjectIndex
Listbox1.CellValueAt(ListBox1.LastAddedRowIndex, 1) = Runtime.ObjectClass(i)
Listbox1.CellValueAt(ListBox1.LastAddedRowIndex, 2) = Runtime.ObjectRefs(i).ToString

TextField1.Value = Str(Runtime.MemoryUsed)+ " " + Str(Runtime.MemoryUsed - PreviousMem)
TextField2.Value = Str(Listbox1.RowCount)
PreviousMem = Runtime.MemoryUsed

There are NO processes inside a Xojo app you are debugging
At most you might have other threads but threads are not processes when you use Xojo threads

Think of a process as “another running application”

Okay, so running one XOJO program is just one process. Should I concentrate on a log file to help determine why my program was hanging when using a thread?

I dont think there’s any hard and fast yes or no answer to this
A log file of some sort may help figure out why things would hang
So might actually just posting some of the code in the threads run event

note that threads are NOT preemptive and so they CAN cause an app to hang if

  • they call external libraries that do not yield
  • they perform tight loops that do not yield
1 Like

If yours is a program that should run continuously, you might look at providing it with some infrastructure. Mine has a logging area where messages are displayed and scroll off the top, but such messages are also logged to a disk file. I have a housekeeping thread that runs once an hour and, inter alia, checks the length of the log file. If over (say) 500kb, it renames and compresses it and creates a new one. Put logging messages anywhere. If you have threads you’ll need to organise that they can add messages to the logging area, if you have one, without getting a ThreadAccessingUIException.

Seems you’re interacting with serial ports. Are you just reading, or writing to them too?