views:

62

answers:

1

I'm writing a bunch of scripts that present images serially (e.g. 1 per second) and require the user to make either a keyboard or mouse response.

I'm using closures to handle the timing of image presentation and user input. This causes garbage collection to happen pretty frequently and I'm wondering if that will affect the performance (viz. timing of image presentation).

A: 

Depends on how the closures work and the images. For instance a system which has about 5 different images but 20 different kinds of input would run more efficient if the closures know about the image but take the user input as argument, rather than vice versa -- because you can make do with a maximum of 5 of those closures at any given time as opposed to about 20.

Also you might be able to convert this into a system that works like:

  1. Image display object a single instance of which can be re-used over multiple images (it should contain only the most limited amount of state).
  2. User input functions/objects which trigger events.
  3. Event handler for user input which reconfigures (1) depending on the things emited by (2).