Re: PilBox & Java object lifecycle

2023-08-26 Thread Todd Coram
On Fri, Aug 25, 2023, at 3:52 AM, Alexander Burger wrote:

> and did some test. Works fine, and gives - as expected - a null pointer
> exception if the object is accessed from Lisp again.

Great! I've got same results here.  Of course, tracking every object 
instantiation that gets stuffed into the HashArray isn't trivial, but for my 
purposes it's essential.  It seems that any object returned by a Java method 
call is subject to be placed there so calls like (java (java someobject 
'getResultingObject) 'doSomething)) will place the inner object in the 
HashArray, correct?
I've taken to not doing nested (java) calls to manage this.  And I've also 
wrapped a catch around my releases (java NIL obj) in case it has been release 
already from the HashArray...  Some good idioms will need to go with the use of 
(java NIL...) 

> I cannot make a release to PlayStore now, as PilBox is in the process of some
> changes to prepare for Android 14. So I made a temporary release available at:
>
>https://picolisp.com/pub/pilBox.apk
>https://picolisp.com/pub/PilBox.tgz

Thanks! I'll grab it soon.

> Thanks a lot for the good idea! :)

Thanks for validating it.  My app has now been running over 24 hours 
(collecting BLE scans) without running out of memory (up from the 1-2 hour runs 
before).

/todd

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: PilBox & Java object lifecycle

2023-08-26 Thread Alexander Burger
On Sat, Aug 26, 2023 at 11:56:42AM -0400, Todd Coram wrote:
> Of course, tracking every object instantiation that gets stuffed into the
> HashArray isn't trivial,

The opposite (i.e. which objects are still referenced from Lisp) is easy though:

   (filter
  '((Obj) (== 32769 (car (id Obj T
  (all 0) )

This returns a List of all accessible Java objects.


> It seems that any object returned by a Java method call is subject to be 
> placed
> there so calls like (java (java someobject 'getResultingObject) 'doSomething))
> will place the inner object in the HashArray, correct?

Yes. The call inserts the result of (java someobject ...) into the hashmap, and
perhaps also the result of the outer 'java' call if it is an object.

For example,

   : (java "java.io.File" T "name")
   -> {H@@@10327432}

inserts *one* new object.

If that object's internals are accessed, for example by

   : (show @)
   {H@@@10327432} ({H@@@751603011} . "java.io.File")
  filePath NIL
  path "name"
  prefixLength 0
  status NIL
  fs {H@@@1172500016}
  pathSeparator ":"
  pathSeparatorChar 58
  separator "/"
  separatorChar 47
  serialVersionUID 301077366599181567
   -> {H@@@10327432}

then also all objects referred by it (i.e. {H@@@751603011} and {H@@@1172500016}
will be inserted.

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe