Hi Emeliyan,
First of all, PACKAGEBY doesn't work with RUNALLOCATION; your initial question was about WHEN/ENDWHEN.
My understanding of that script this script is it erasing all data in the Model. It would be easier just to drop data from the cube. This script will work forever on your 15M records.
If you still want to use something similar I'd suggest looping on all sub nodes of the top node or run each FOR/NEXT loop on some property. RUNALLOCATION commits data after every END....
This will take reasonable time and should not run out of memory.
Regards,
Gersh