Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:03:53+00:00 2026-06-02T10:03:53+00:00

i am writing an app which does file downloading from a web service. The

  • 0

i am writing an app which does file downloading from a web service.

The way how files are downloaded is described as follows:

  1. 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.
  2. 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.
  3. Do some business logic here.
  4. Download the next group of file if any.

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:

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

   <My Business Logic here>

} while(group.hasMoreGroups());

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.

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.

Please give your opinion.

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:03:54+00:00Added an answer on June 2, 2026 at 10:03 am

    Creating 1000 LinkedList objects (and garbage-collecting them) has a negligible cost compared to downloading millions of files. We’re talking about 1 milli-second vs. hours here. Some meters vs. the distance from the earth to the moon.

    You’re pre-optimizing, and as is usually the case when pre-optimizing, you’re doing it at the wrong place.

    That said, a list is a dynamically sized data structure, and you don’t need to know its maximum size to be able to reuse it. It will grow dynamically:

    List<FileDescriptor> list = new LinkedList<FileDescriptor>();
    do {
        list.clear(); // remove everything from the list
        ...
    }
    while (...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a web app which works on subdomains. I would also like
I am writing an asp.net web app which involves the use of the FileUpload
I'm writing a small Scala app that does the following: 1) Read XML/XHTML files
I'm writing an iPhone app which fetches an XML file, parses it and then
I am writing an iPhone app which takes video from the camera, runs it
I'm writing an app which for various reasons involves Internet Explorer (IE7, for the
I am writing an app which needs to have both the traditional form of
I am writing an app which is going to be displaying images found on
I'm writing an app which will be used mainly on phones, but which some
I'm writing a WinForms app which has two modes: console or GUI. Three projects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.