if you allocate the array on the heap it won't run out of scope, but on the other hand it leaves the possibility the client could forget to delete it, so from a OOP perspective returning an array on the heap is bad programming practice. You should pass an array instead, and then if you want, return a reference to it