Using Java collection in this scenario
<p>i am writing an app which does file downloading from a web service. </p>

<p>The way how files are downloaded is described as follows:</p>

<ol>
<li>From the web service, download a list of files. If the number of files is too big, download the first group of files, the maximum number in each group is unknown. Downloaded files are saved in system temp directory.</li>
<li>For each file, construct a FileDescriptor (customed) class which contains the files filename and the temporary filename in the system temp folder and some other attribute.b The FileDescriptor is saved in a list.</li>
<li>Do some business logic here.</li>
<li>Download the next group of file if any.</li>
</ol>

<p>The collection I used to save the list of FileDescriptor is LinkedList. However, for each group of files, I am going to create a brand new LinkedList to hold their FileDescriptors. The Psudocode is something like:</p>

<pre><code>do {
   List&lt;FileDescriptor&gt; list = new LinkedList&lt;FileDescriptor&gt;();
   GroupOfFiles group = webService.getGroupOfFiles();
   Iterator&lt;File&gt; itr = group.iterator();
   while(itr.hasNext) {
       list.add(new(FileDescriptor(itr.next()));
   }

   &lt;My Business Logic here&gt;

} while(group.hasMoreGroups());
</code></pre>

<p>As can be seem, everytime a new group of files is retrieved, I am going to create a new LinkedList. After the group of files are processed, the LinkedList is no longer needed. I cannot create one list and reuse it because the maximum number each group can contain is unknown.</p>

<p>If I use the code like this and there are millions of files, each group can only up to 1000 file for example, it will end up with a lot of LinkedList (and its element) as Garbage. Is this something good to do? I am sure there will be better ways to handle it in this scenario.</p>

<p>Please give your opinion.</p>

<p>Many thanks.</p>
