From: <cro...@li...> - 2005-01-12 20:10:28
|
Module Name: CFJavaEditor Committed By: tchize Date: Wed Jan 12 20:10:19 UTC 2005 Modified Files: CFJavaEditor/src/cfeditor: ArchObjectStack.java CFileInputStream.java FaceObject.java Added Files: CFJavaEditor/src/cfeditor: TrackedBufferedInputStream.java Log Message: Fixed a memory consumption problem in editor. Now all png are lazy loaded (when first drawn) and are soft referenced (can be garbage collected). Overall, 5 maps loaded in editor makes the jvm consume about 25M total. The following files had too many changes to show the context diffs here: cvs rdiff -r1.17 -r1.18 CFJavaEditor/src/cfeditor/ArchObjectStack.java Start of context diffs Index: CFJavaEditor/src/cfeditor/CFileInputStream.java diff -c CFJavaEditor/src/cfeditor/CFileInputStream.java:1.4 CFJavaEditor/src/cfeditor/CFileInputStream.java:1.5 *** CFJavaEditor/src/cfeditor/CFileInputStream.java:1.4 Sun Jan 9 14:05:34 2005 --- CFJavaEditor/src/cfeditor/CFileInputStream.java Wed Jan 12 12:10:18 2005 *************** *** 45,51 **** // streams private FileInputStream fileInput; // binary file input stream private InputStream inStream; // basic binary input stream ! private BufferedInputStream stream; // buffered stream /** * Constructor: Open a byte-stream to the specified resource file. --- 45,51 ---- // streams private FileInputStream fileInput; // binary file input stream private InputStream inStream; // basic binary input stream ! private TrackedBufferedInputStream stream; // buffered stream /** * Constructor: Open a byte-stream to the specified resource file. *************** *** 73,79 **** // first we look if the resource is available as normal binary-file // in the specified directory fileInput = new FileInputStream(filedir +File.separator+ filename); ! stream = new BufferedInputStream(fileInput); is_binfile = true; } catch(FileNotFoundException e) { --- 73,79 ---- // first we look if the resource is available as normal binary-file // in the specified directory fileInput = new FileInputStream(filedir +File.separator+ filename); ! stream = new TrackedBufferedInputStream(fileInput); is_binfile = true; } catch(FileNotFoundException e) { *************** *** 81,87 **** // second we look if the resource is available as normal binary-file // in the editor's root directory fileInput = new FileInputStream(filename); ! stream = new BufferedInputStream(fileInput); is_binfile = true; } catch(FileNotFoundException ex) { --- 81,87 ---- // second we look if the resource is available as normal binary-file // in the editor's root directory fileInput = new FileInputStream(filename); ! stream = new TrackedBufferedInputStream(fileInput); is_binfile = true; } catch(FileNotFoundException ex) { *************** *** 89,95 **** // the system-jar-archive: inStream = ClassLoader.getSystemResourceAsStream(filename); if (inStream != null) { ! stream = new BufferedInputStream(inStream); is_jar = true; } } --- 89,95 ---- // the system-jar-archive: inStream = ClassLoader.getSystemResourceAsStream(filename); if (inStream != null) { ! stream = new TrackedBufferedInputStream(inStream); is_jar = true; } } *************** *** 105,111 **** /** * @return <code>BufferedInputStream</code> to the resource file */ ! public BufferedInputStream getBufferedStream() {return stream;} /** * Read one byte from the stream --- 105,111 ---- /** * @return <code>BufferedInputStream</code> to the resource file */ ! public TrackedBufferedInputStream getBufferedStream() {return stream;} /** * Read one byte from the stream Index: CFJavaEditor/src/cfeditor/TrackedBufferedInputStream.java diff -c /dev/null CFJavaEditor/src/cfeditor/TrackedBufferedInputStream.java:1.1 *** /dev/null Wed Jan 12 12:10:21 2005 --- CFJavaEditor/src/cfeditor/TrackedBufferedInputStream.java Wed Jan 12 12:10:18 2005 *************** *** 0 **** --- 1,85 ---- + /* + * Created on 12 janv. 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ + package cfeditor; + + import java.io.BufferedInputStream; + import java.io.IOException; + import java.io.InputStream; + + import org.apache.log4j.Logger; + + /** + * @author tchize + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ + public class TrackedBufferedInputStream extends BufferedInputStream { + private static Logger log = Logger.getLogger(TrackedBufferedInputStream.class); + + private long position = 0; + private long lastPosition = -1; + + public TrackedBufferedInputStream(InputStream stream) { + super(stream); + } + public TrackedBufferedInputStream(InputStream stream, int size) { + super(stream, size); + } + /* (non-Javadoc) + * @see java.io.InputStream#mark(int) + */ + public synchronized void mark(int max) { + // TODO Auto-generated method stub + super.mark(max); + lastPosition = position; + } + /* (non-Javadoc) + * @see java.io.InputStream#read() + */ + public synchronized int read() throws IOException { + // TODO Auto-generated method stub + int result = super.read(); + if (result>=0) + position++; + return result; + } + /* (non-Javadoc) + * @see java.io.InputStream#read(byte[], int, int) + */ + public synchronized int read(byte[] data, int offset, int length) + throws IOException { + // TODO Auto-generated method stub + int result = super.read(data, offset, length); + if (result>0) + position+=result; + return result; + } + /* (non-Javadoc) + * @see java.io.InputStream#reset() + */ + public synchronized void reset() throws IOException { + // TODO Auto-generated method stub + super.reset(); + position = lastPosition; + } + /* (non-Javadoc) + * @see java.io.InputStream#skip(long) + */ + public synchronized long skip(long count) throws IOException { + // TODO Auto-generated method stub + long realSkipped = super.skip(count); + position+=realSkipped; + return realSkipped; + } + + public long getPosition(){ + if (log.isDebugEnabled()) + log.debug("getPosition : "+position); + return position; + } + } |