Added checks for program size restraints and cleared resident queue when clearing memory