It looks like you're not constructing a proper reference to your instance manager. The easy way to do it is to prefix the subform name with an "_". e.g. if your subform is named "detailLine", then the instance manager will be named "_detailLine".
To remove all instances, code:
_detailLine.count = 0;
(No need to use a loop).
If you want to selectively delete subform instances, then reference _detailLine.removeInstance() in a loop.
The reason I'm using a loop is to stream line the removal/setting the count of several pages, for example Page 2 through 4. Within the loop I concatenate "Page" with String(i) and set it as the variable "page". For some reason this variable is not playing nicely with the instance manager. I am able to get message boxes when I DO NOT attempt to call the instance manager with the variable to read "Page4", "Page3", "Page2" and so on until the loop is exhausted so I know that I'm concatenating correctly. When I place the instance manager in there with the variable the loop does not continue and breaks. And I know that the loop breaks because if I call the message box above my call to the instance manager I get a message box with "Page4" but nothing after that.