move temporary memory handling to rtimag routines