How to cache complex item into texture and release the memory for the actual complex item?



  • I've got a big number of items that are quite complex (memory-heavy), and in order to fit in limited RAM, I want to cache some of them into textures and not keep the actual complex item in memory. In particular, items for which I want to do that are all those (among my complex items) that do not currently need to animate (and this means most of them). For the purposes of this question I call this kind of items "inactive".

    My plan was:

    • When an item "foo" becomes inactive:
      • Create dynamically a ShaderEffectSource (with no associated ShaderEffect) with live: false; source: foo, in the same rectangle that was occupied by foo.
      • call scheduleUpdate() on the ShaderEffectSource
      • when the ShaderEffectSource becomes updated, call destroy() on foo

    The problem with this plan is with the "when the ShaderEffectSource becomes updated" thing: there is no signal to notify me when that happens. I could use the fact (from the docs) that scheduleUpdate() schedules the update for the next frame. So I would maybe start a Timer that looks something like this:

    Timer {
    	interval: 1 // 1ms interval meaning "fire every frame"
    	property int timesTriggered: 0
    	repeat: true
    	running: false
    	
    	onTriggered: {
    		timesTriggered++;
    		if(timesTriggered == 2) {
    			complexItem.destroy();
    			running = false;
    		}
    	}
    }
    

    The == 2 check is to ensure that we've not only reached the next frame (which doesn't guaranteed that the scheduled update has happened already), but we've also reached the frame after that.

    But that approach is a hack. Any approach that is not a hack?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.