[mapguide-trac] #1294: custom output causes memory leak?

MapGuide Open Source trac_mapguide at osgeo.org
Mon Mar 15 05:53:05 EDT 2010


#1294: custom output causes memory leak?
----------------------------------------------+-----------------------------
 Reporter:  ioly                              |         Owner:       
     Type:  defect                            |        Status:  new  
 Priority:  medium                            |     Milestone:       
Component:  Web API                           |       Version:  2.0.2
 Severity:  critical                          |    Resolution:       
 Keywords:  custom output render memory leak  |   External_id:       
----------------------------------------------+-----------------------------
Comment (by ioly):

 I've found a way to avoid this problem. I notice the "MgByteReader.ToFile"
 method
 and I use it to avoid calling "MgByteReader.Read",then it seems working
 stably.

 '''original code:'''
 {{{
         byte[] tmp = new byte[1024 * 1024];
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         while (true) {
             int len = byteReader.Read(tmp, tmp.length);
             log(len);
             if (len > 0) {
                 buffer.write(tmp, 0, len);

             } else {
                 break;
             }
         }
 }}}


 '''new code:'''
 {{{
         File file = File.createTempFile(session.getSessionId(), ".png");
         byteReader.ToFile(file.getAbsolutePath());

         FileChannel channel = new FileInputStream(file).getChannel();
         ByteBuffer buf = ByteBuffer.allocate((int)channel.size());
         while(buf.position() < buf.capacity()){
             channel.read(buf);
         }

         channel.close();
         tmp = buf.array();
         file.delete();
         buf.clear();
 }}}

 It's not graceful, but works.

-- 
Ticket URL: <http://trac.osgeo.org/mapguide/ticket/1294#comment:4>
MapGuide Open Source <http://mapguide.osgeo.org/>
MapGuide Open Source Internals


More information about the mapguide-trac mailing list