Frage

In my wicket application, Page navigation is by creating new Page object by calling the constructor of the new Page on the onClick() methods. As below.

DisplayItem.add(new Link("edit") { 
@Override
   public void onClick() {
    try{
    setResponsePage(new ReportPage(object, getPageReference()));
       } catch ( CustomException e){
          /// set some feedback message
        }
   }
});

ReportPage has several LoadableDetachableModels, PageableListViews, Panels, Fragments etc. I am doing exception handling in the constructor of the ReportPage and throws it back if an exception occurs. Ses below. ( partial code )

 public ReportPage(final Objectm, final PageReference pr) throws CustomException{

try{
final LoadableDetachableModel<MaintReport> ldm = 
         new LoadableDetachableModel<MaintReport>() {

            @Override
            protected MaintReport load() {
                return new MaintReport();
            }
        };

/*

Several LoadableDetachableModels, PageableListViews, Panels, Fragments  etc.

*/ 


} catch ( Exception ex){
// create Custom Exception 

} finally {

 // Clean up of stuff 

}

So if an exception occurs in constructing the page. How should I do clean up ( in the finally block ) ? . Should I set all the individual objects to null ? Is there any Wicket method to garbage collect ( or send signal to GC) ?

Thank you

War es hilfreich?

Lösung

Throwing an exception form within a constructor immediately makes the half initialized object eligible for garbage collection. Unless you are somehow preventing it by say adding the object into a collection owned by another object before the exception was thrown, there is no need to worry about the deallocation of this object and its fields. You still need to release any unmanaged resources that may have already been allocated (e.g. file handles) as you would normally do in your finally block.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top