Fix memory bug causing apps to hang the system