emit memory init files when closure is run, fixes #1547