Effectively I forgot to close the for method... Now, it work's fine! I think that after a lot of hours with the nose through the code, I didn't see anything...
Otherwise, I create (def) the $elements varliable in each loop because I hope that "{undef}" free memory. Do you know:
1/ If it's true ? 2/ if I use {set ...}, the memory is spared too?
Do you know where can I find an exemple who "use native PHP functions instead of Template code" for doing this ?
native PHP: you can create a simple template fetch function or module which would do the same work for you and generate the html, but much more efficient - because of the loops and fetches.