You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Eduardo Piva <ed...@gwe.com.br> on 2005/08/10 00:56:47 UTC

Setting null in a lazy-load object.

Hi List,

I have a group of objects that I'm using in my project, and part of them I'm populating via lazy-load, because they are ralelly used (there are some object's that are used only to show information in the screen or in reports). I have some process, in my back-end, that uses and create all these objects.

There are some information that are used (and loaded via lazy-load) and are used again just some minutes before the first usage. I would like to do something like resetting all lazy-load objects, using something like: object.setLazyParameter(null), to enable the garbage collector to fre this space for me, but I don't want to verify, in many places in my project, if this parameter is null, like:

if (object.getLazyParameter() == null) { myDAO.populateLazyParameter ... }.

I would like to free my object reference and, when I need to get it again, ibatis verifies that the parameter is null again and get it again. Is it possible? I'm needing this because I'm having memory usage problems here and I don't want to set the parameter to null, since there are a lot of places that uses it and I would eventually cause a null pointer exception, and I don't wan't to hold references to unused objects in memory (they become unused for some minutes).

That's it.

Thank's.

----
Eduardo Piva
GWE Software
+55 (19) 3254-7633
+55 (19) 8114-9488
www.gwe.com.br


Re: Setting null in a lazy-load object.

Posted by Clinton Begin <cl...@gmail.com>.
There's nothing that iBATIS can do in this regard. But you could create a 
dynamic proxy (see CGLIB) for the class that holds the property, and you can 
write the code to check for null and load on demand.

However you must be dealing with absolutely ENORMOUS objects or MILLIONS of 
them to worry about such a thing. Even so, I'd suggest reducing the number 
of top level objects in use in your system (e.g. paginate result sets, 
scrollable result sets etc.). 

Messing with the depth and completeness of an object for the sake of saving 
memory will probably be worth less than it will cost you in the long run.

Cheers,
Clinton

On 8/9/05, Eduardo Piva <ed...@gwe.com.br> wrote:
> 
> Hi List,
> 
> I have a group of objects that I'm using in my project, and part of them 
> I'm populating via lazy-load, because they are ralelly used (there are some 
> object's that are used only to show information in the screen or in 
> reports). I have some process, in my back-end, that uses and create all 
> these objects.
> 
> There are some information that are used (and loaded via lazy-load) and 
> are used again just some minutes before the first usage. I would like to do 
> something like resetting all lazy-load objects, using something like: 
> object.setLazyParameter(null), to enable the garbage collector to fre this 
> space for me, but I don't want to verify, in many places in my project, if 
> this parameter is null, like:
> 
> if (object.getLazyParameter() == null) { myDAO.populateLazyParameter ... 
> }.
> 
> I would like to free my object reference and, when I need to get it again, 
> ibatis verifies that the parameter is null again and get it again. Is it 
> possible? I'm needing this because I'm having memory usage problems here and 
> I don't want to set the parameter to null, since there are a lot of places 
> that uses it and I would eventually cause a null pointer exception, and I 
> don't wan't to hold references to unused objects in memory (they become 
> unused for some minutes).
> 
> That's it.
> 
> Thank's.
> 
> ----
> Eduardo Piva
> GWE Software
> +55 (19) 3254-7633
> +55 (19) 8114-9488
> www.gwe.com.br <http://www.gwe.com.br>
> 
>