Garbage collection in Java recursion

Source: Internet
Author: User

The most recent tool for working with database-guided data is to copy the official line's project to the test environment before the iteration, and perform the upgrade to see if the functionality is complete.

So it involves reading the data on the JDBC page and then storing it in the test environment database. Recursion is used where paging is handled.

Tools are delivered to test colleagues, most projects can be copied successfully, but some of the large data volume of the project has failed, the initial focus is on the database data, because the more disgusting is that the database has more binary fields, super large text. The failure is that when data is directed to a large table, it hangs up and keeps up with the MySQL record that hangs up, discovering that the amount of data is not as big as it should be. Later found in the log corner of the memory leak, OK, with the database does not matter, a line of check code. Finally see the Recursive code!


There is a garbage collection mechanism in Java, in theory, after a method has been executed, the resources that are applied within the method are recycled, but the recursion is really different, and after the end of the recursion, the resources used by the intermediary application are not released. My scene, the recursive query to the source data collection list, very large, when recursive to a certain extent, will inevitably hang out. In fact, in the recursive, for the comparison of the larger object of the declaration, the direct null can be, the garbage collection mechanism will reclaim the variables declared in these recursion.


That is, the reference to the stored object in the stack, and the base data type, the storage object in the heap, the reference to the object in the heap only, the reference to null, then the object in the heap is not referenced, then the resources requested in the heap are reclaimed.

Directly on the code:

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/26/61c8da2b338a5ac5e28333d5692b3b0f.png-wh_500x0-wm_3 -wmp_4-s_217814147.png "title=" Qq20171026143225.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style= "width:700px;height:130px;" alt= "61c8da2b338a5ac5e28333d5692b3b0f.png-wh_"/>

Garbage collection in Java recursion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.