Memory leak in apply