[sikuli-java] Share a Screen instance or re-create a new one

Asked by Pathiyil

Hi,

A question on best practice with sikuli-java - regarding the 'cost' of creating Screen objects:

I have a collection of tests. Is it a better practice to instantiate the Screen object once and use that in all the tests or instantiate a Screen object in each test ? In other words is Screen class heavy in terms of creation or the amount of resources it uses ?

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

A Screen object (which inherits from Region) itself is lightweight, since it only contains some numbers and some references. The only heavy "reference" is the last screenshot. But since this is created and changed with every find operation, this does not affect object creation and the older captures are available to GC anyway.

In your case it does not matter anyway: each test case creates it's own local environment, where all created objects are eligible for GC at exit from the test case.

So taking into account the additional effort of passing around a global screen object this does not make sense.

Conclusion: create Screen/Region objects wherever/whenever needed. Reusing these objects can be restricted to the block context.

Revision history for this message
Pathiyil (pathiyil) said :
#2

Thanks RaiMan, that solved my question.