Change how object memory is allocated; this also fixes the problem with crashing if there are too many objects.