I assume you are building your array in a shift register. You need to initialize with an empty array (Size zero!) or the shift register will retain the data from the previous run.
I really don't understand your problem. Initializing your shift register with an empty array is peanuts. Just do it and don't worry about it.
Be aware that building an array in a loop can cause performance issues because more memory needs to be allocated as the array grows. However, there will never be any "trailing zeroes".
(If you want to be more efficient AND you know the final array size, you should initialize the shift register with an array of the final size (containing all zeroes or INF, for example). Then you can use "replace array element" at the desired indes as you go. SInce you don't know the final size, you cannot do this)
A finite size array filled with zeroes is very different to an empty array, is it possible that you confuse the two? 😉
Describe in more detail what you are actally doing, how you are building the array, etc. and we can give more detailed help. 🙂
What are your typical upper arrray size limits? (a few hundred? a few hundred million?)