I have been asked this question several times. لقد طلب مني في هذه المساله عدة مرات. Recently Xyling asked the same question in his blog. في الآونة الاخيرة وطلب xyling السؤال نفسه في تقريره بلوق. So I thought a simple explanation may be in order. كنت اعتقد حتى مجرد تفسير يمكن ان تكون في النظام.

To unload a class you have to create a custom classloader and load the class using it. لتفريغ فئة لديك لايجاد عرف classloader وتحميل الطبقة استخدامه. Tomcat does it and so does JRun. قط وانه لا.. فهل jrun. You can look in Tomcat code for an example. يمكنك أن تبحث في مدونة قط على سبيل المثال.

After you are done with the class you need to release all references to the class as well as to the class loader by reassigning the variables or setting them to null. بعد انتهائك مع الطبقة انت بحاجة الى اطلاق سراح جميع الاشارات الى الطبقة وكذلك الى اعادة تكليف من قبل الطبقة محمل المتغيرات او تحديد لها لاغيه.

Then either wait for System.gc() to unload the class or you call it directly in a loop till no more bytes can be freed. بعد ذلك اما ان ننتظر system.gc () لتفريغ أو الطبقة أو الدعوة لكم فيه مباشرة في حلقة حتى لا اكثر بايت يمكن ان تتحرر. however normally calling it twice does the trick. ولكن عادة مرتين ووصفه بانه لا حيلة.

Note: You cannot unload a single class. ملاحظه : لا يمكنك تفريغ فئة واحدة. You have to unload the classloader along with it. لديك لتفريغ classloader معه. So obviously System classloader is not the suitable for this task. ومن الواضح ان ذلك النظام classloader ليست مناسبة لهذه المهمة.

Note 2: This is how JSP pages are reloaded dynamically everytime you change the code. ملاحظه 2 : التخطيط الاستراتيجي المشترك وهذه هي الطريقة التي يتم اعادة تحميل صفحات ديناميكيه في كل مرة تقوم بتغيير هذا القانون. And yes that is why first time takes much longer to load then subsequent times. نعم وهذا هو السبب في المرة الاولى يأخذ وقتا اطول لتحميل اوقات لاحقة بعد ذلك.