Xojo Conferences
XDCMay2019MiamiUSA

Runtime.ObjectCount incorrect? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Text versus Binary - was Re: Storing Application Settings
Next thread: Re: Structures


Getting ListBox Cell Left and Top   -   Rubber Chicken Software Co.
  Runtime.ObjectCount incorrect?   -   Michael Diehr
   Re: Runtime.ObjectCount incorrect?   -   Dr Brian R Gaines

Runtime.ObjectCount incorrect?
Date: 10.08.09 17:17 (Mon, 10 Aug 2009 09:17:11 -0700)
From: Michael Diehr
I'm having a terrible time getting Runtime to work properly in a multi-
threaded app.

I posted this on July 7 but I think the email bounced, so re-posting
again.
This has already been FBd as 8465.

Since that time, I have an additional theory:

Runtime fails in a multithreaded app *because* of a side-issue:
dim props() as introspection.PropertyInfo =
Introspection.getType(o).GetProperties
yields.

So, my theory is this:

In a single-threaded app, calls to Runtime work fine.
In a multi-threaded app, calls to Runtime often fail, because
(internally) runtime is using Introspection -- and on occasion,
introspection is yielding to other threads. Other threads, of
course, may allocate or deallocate object instances. It's my hunch
that when this happens, Runtime gets confused and starts returning
nonsense values.

We had a discussion a while back where I claimed "Framework calls
should *not* yield time without very good reason and
documentation". If my theory above is true, I'd argue this is a
very good example of problems that crop up.

Norman -- any hope of fixing this? I think the fix here is for you
guys to put
#pragma DisableBackgroundTasks
inside every Introspection module.

Original report below:

Runtime.ObjectCount is returning invalid values.
Runtime.MemoryUsed, however seems to always return the correct value.

The following code in a pushbutton will occasionally give me a very
small # of objects.
Click once and get 5601 objects (the correct #). Click again and get
21 objects. Click again, get 5 objects. Click again, get 91 objects.
Click again, 91 objects.

It seems to be triggered when threads are working in the background.
However, the code that calls Runtime.ObjectCount is NOT in a thread.

Is anyone else using runtime.ObjectCount? Have you seen it malfunction?

Window1.Pushbutton1.Action:
#pragma DisableBackgroundTasks
Dim i, u as integer
dim dClasses as new Dictionary
dim dRefCount as new Dictionary
ListBox1.DeleteAllRows
u=Runtime.ObjectCount-1
' group / add up objects
For ito u
dim cls as string = runtime.objectClass(i)
dClasses.value(cls) = dClasses.Lookup(cls,0) + 1
dRefCount.value(cls) = dRefCount.Lookup(cls,0) +
runtime.ObjectRefs(i)
Next

' put in listbox
For each k as variant in dClasses.Keys
listbox1.addrow k
Listbox1.Cell(listbox1.LastIndex,1)ðrmat(dClasses.value(k), "#")
Listbox1.Cell(listbox1.LastIndex,2)=Str(dRefCount.value(k))
Next

StaticText1.text="MemUsed=" + format(runtime.memoryUsed, "#")
StaticText2.text="ObjectCount=" + format(u+1, "#")

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Runtime.ObjectCount incorrect?
Date: 10.08.09 19:34 (Mon, 10 Aug 2009 11:34:02 -0700)
From: Dr Brian R Gaines
Hi Micahel, just to confirm I have noticed ridiculously small numbers
of objects reported in the log of my web server built with REALbasic
and wondered why. Your diagnosis is very helpful and it would be good
to get the problem fixed as the object count is an important
diagnostic of memory leaks in complex apps which may be implicitly
using multi-threading even if not explicitly programmed, b.

>I'm having a terrible time getting Runtime to work properly in a
>multi-threaded app.
>
>I posted this on July 7 but I think the email bounced, so re-posting again.
>This has already been FBd as 8465.
>
>Since that time, I have an additional theory:
>
>Runtime fails in a multithreaded app *because* of a side-issue:
> dim props() as introspection.PropertyInfo =
>Introspection.getType(o).GetProperties
>yields.
>
>So, my theory is this:
>
>In a single-threaded app, calls to Runtime work fine.
>In a multi-threaded app, calls to Runtime often fail, because
>(internally) runtime is using Introspection -- and on occasion,
>introspection is yielding to other threads. Other threads, of
>course, may allocate or deallocate object instances. It's my
>hunch that when this happens, Runtime gets confused and starts
>returning nonsense values.
>
>We had a discussion a while back where I claimed "Framework calls
>should *not* yield time without very good reason and documentation".
>If my theory above is true, I'd argue this is a very good example of
>problems that crop up.
>
>Norman -- any hope of fixing this? I think the fix here is for
>you guys to put
>#pragma DisableBackgroundTasks
>inside every Introspection module.
>
>Original report below:
>
>Runtime.ObjectCount is returning invalid values.
>Runtime.MemoryUsed, however seems to always return the correct value.
>
>The following code in a pushbutton will occasionally give me a very
>small # of objects.
>Click once and get 5601 objects (the correct #). Click again and
>get 21 objects. Click again, get 5 objects. Click again, get 91
>objects.
>Click again, 91 objects.
>
>It seems to be triggered when threads are working in the background.
>However, the code that calls Runtime.ObjectCount is NOT in a thread.
>
>Is anyone else using runtime.ObjectCount? Have you seen it malfunction?
>
>Window1.Pushbutton1.Action:
>#pragma DisableBackgroundTasks
>Dim i, u as integer
>dim dClasses as new Dictionary
>dim dRefCount as new Dictionary
>ListBox1.DeleteAllRows
>u=Runtime.ObjectCount-1
>' group / add up objects
>For ito u
> dim cls as string = runtime.objectClass(i)
> dClasses.value(cls) = dClasses.Lookup(cls,0) + 1
> dRefCount.value(cls) = dRefCount.Lookup(cls,0) + runtime.ObjectRefs(i)
>Next
>
>' put in listbox
>For each k as variant in dClasses.Keys
> listbox1.addrow k
> Listbox1.Cell(listbox1.LastIndex,1)ðrmat(dClasses.value(k), "#")
> Listbox1.Cell(listbox1.LastIndex,2)=Str(dRefCount.value(k))
>Next
>
>StaticText1.text="MemUsed=" + format(runtime.memoryUsed, "#")
>StaticText2.text="ObjectCount=" + format(u+1, "#")
>
>_______________________________________________
>Unsubscribe or switch delivery mode:
><http://www.realsoftware.com/support/listmanager/>
>Search the archives:
><http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>