Java Memory leak Quiz

Source: Internet
Author: User
Package com.ckw.mianshi;/** * Test memory leaks * Several events in Java that cause memory leaks: * A reference to an object that is held in a container such as 1.hashmap,verctor, although the object is already set to NULL, a memory leak * 2 will still occur. The use of the Listener class, no display is set to NULL * 3. The Close method of the database connection class did not call * 4. A reference to another class in a singleton mode * @author Administrator * */import java.util.vector;public CL memoryleak {static Vector<object> v = new Vector<object> (Ten);p ublic static void Main (string[] args) {long Starttime=system.currenttimemillis ();   Gets the start time for (int i=0; i<10; i++) {Object o = new Object (); V.add (o); o = null;//even if O is still holding object o in Null,v, resulting in memory leaks}// The correct practice is to use the V-space//v = Null;long endtime=system.currenttimemillis () after using V; Get End Time System.out.println ("program Run Time:" + (Endtime-starttime) + "MS");}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Memory leak Quiz

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.