search

Home  >  Q&A  >  body text

javascript - How do you deal with some useless data in objects~

Request data from the backend interface and return user information and a website list

User information cannot be used anywhere else after the request is returned and displayed. However, the user website list needs to be used everywhere

When using the website list, should I directly use the returned data object or create a new object and put the data of the website list into it?

If you use the original data object, the user information contained in the object and some other useless data cannot be recycled, which is unpleasant and wastes memory...

给我你的怀抱给我你的怀抱2705 days ago876

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-07-05 11:04:55

    What you need to know is that the interpreter in scripting language programming comes with a memory recycling mechanism. You can check the heap memory usage and automatic recycling of the page in Chrome's Performance.

    The reality is that the amount of data used to render the page is much smaller than the current machine threshold level. For example: In my map library http://sinomap.ewind.us, there are 2000 horizontal lines of JSON data representing China's terrain, each with 10 simple numbers and 100 characters of strings. A simple calculation is performed at a full frame rate of 60fps, and the memory usage is only about 30M. The so-called "waste of memory" worry is unrealistic in most cases.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-07-05 11:04:55

    1. Creating a new data object and then copying the data is the most wasteful solution, including CPU and memory;

    2. Use the original data directly without processing, which takes up a little memory;

    3. Delete useless data after obtaining the original data, which takes up CPU and execution time;
      In comparison, usually choose 2. For user experience, response speed is more important than memory, unless the memory OOM occurs.

    reply
    0
  • Cancelreply