Common subdirectories: khtmlw.org/CVS and khtmlw/CVS
diff -u khtmlw.org/htmlobj.cpp khtmlw/htmlobj.cpp
--- khtmlw.org/htmlobj.cpp Mon Jan 18 10:57:54 1999
+++ khtmlw/htmlobj.cpp Sat Aug 28 15:05:18 1999
@@ -50,6 +50,12 @@
QDict* HTMLImage::pCache = 0L;
int HTMLObject::objCount = 0;
+// Testing implied that this number was just fine - impact on
+// performance was negligable. Conserving memory is good (tm).
+// It would be best if this could be tuned via. some advanced
+// configuration dialog.
+#define PCACHESIZE 73
+
//-----------------------------------------------------------------------------
HTMLObject::HTMLObject()
@@ -1239,12 +1245,19 @@
//-----------------------------------------------------------------------------
+
HTMLCachedImage::HTMLCachedImage( const char *_filename )
{
pixmap = 0;
filename = _filename;
}
+HTMLCachedImage::~HTMLCachedImage( )
+{
+ if ( pixmap ) delete pixmap;
+ pixmap = 0;
+}
+
QPixmap* HTMLCachedImage::getPixmap()
{
if ( !pixmap )
@@ -1262,7 +1275,8 @@
// yet been initialized. Better be careful.
if( !pCache )
{
- pCache = new QDict( 503, true, false );
+ pCache = new QDict( PCACHESIZE, true, false );
+ pCache->setAutoDelete(TRUE);
return 0l;
}
@@ -1279,10 +1293,16 @@
{
// Since this method is static, it is possible that pCache has not
// yet been initialized. Better be careful.
- if( !pCache )
- pCache = new QDict( 503, true, false );
+ if( !pCache ) {
+ pCache = new QDict( PCACHESIZE, true, false );
+ pCache->setAutoDelete(TRUE);
+ }
- pCache->insert( _filename, new HTMLCachedImage( _filename ) );
+ // Brute force garbage collection. So we take a
+ // performance hit - this should plug the leak!
+ if (pCache->count() > PCACHESIZE/2) pCache->clear();
+
+ pCache->replace( _filename, new HTMLCachedImage( _filename ) );
}
HTMLImage::HTMLImage( KHTMLWidget *widget, const char *_filename,
@@ -1290,8 +1310,10 @@
int _max_width, int _width, int _height, int _percent, int bdr )
: QObject(), HTMLObject()
{
- if ( pCache == 0 )
- pCache = new QDict( 503, true, false );;
+ if ( pCache == 0 ) {
+ pCache = new QDict( PCACHESIZE, true, false );;
+ pCache->setAutoDelete(TRUE);
+ }
pixmap = 0;
movieCache = 0;
@@ -1371,7 +1393,7 @@
}
// Is the image available ?
- if ( pixmap == 0 || pixmap->isNull() )
+ if ( !pixmap || pixmap->isNull() )
{
if ( !predefinedWidth && !percent)
width = 32;
@@ -1427,6 +1449,7 @@
if ( p )
{
*pixmap = *p;
+ cached = true;
}
else
{
@@ -1445,7 +1468,7 @@
}
// Is the image available ?
- if ( pixmap == 0 || pixmap->isNull() )
+ if ( !pixmap || pixmap->isNull() )
{
if ( !predefinedWidth && !percent)
width = 32;
@@ -1485,11 +1508,11 @@
}
else
{
- pixmap = new QPixmap();
+ if ( !pixmap ) pixmap = new QPixmap();
pixmap->loadFromData( _buffer.buffer() );
cached = false;
- if ( pixmap == 0 || pixmap->isNull() )
+ if ( !pixmap || pixmap->isNull() )
return false;
}
@@ -1554,11 +1577,11 @@
}
else
{
- pixmap = new QPixmap();
+ if ( !pixmap ) pixmap = new QPixmap();
pixmap->load( _filename );
cached = false;
- if ( pixmap == 0 || pixmap->isNull() )
+ if ( !pixmap || pixmap->isNull() )
return;
init();
@@ -1596,7 +1619,7 @@
if ( percent > 0 )
max_width = _max_width;
- if ( pixmap == 0 || pixmap->isNull() )
+ if ( !pixmap || pixmap->isNull() )
return;
if ( percent > 0 )
@@ -1816,8 +1839,9 @@
// if ( !imageURL.isEmpty() && !pixmap )
// htmlWidget->cancelRequestFile( this );
- if ( pixmap && !cached )
+ if ( pixmap )
delete pixmap;
+
#ifdef USE_QMOVIE
if ( movie )
{
diff -u khtmlw.org/htmlobj.h khtmlw/htmlobj.h
--- khtmlw.org/htmlobj.h Sun Dec 6 19:55:48 1998
+++ khtmlw/htmlobj.h Sat Aug 28 11:55:06 1999
@@ -571,7 +571,7 @@
{
public:
HTMLCachedImage( const char * );
- virtual ~HTMLCachedImage() { }
+ virtual ~HTMLCachedImage();
QPixmap* getPixmap();
const char *getFileName() { return filename.data(); }
@@ -669,9 +669,9 @@
QString imageURL;
KHTMLWidget *htmlWidget;
-
- static QDict* pCache;
+ static QDict* pCache;
+
/*
* Flag telling wether this image was found in the cache
* If this flag is set, you may not delete the pixmap since the pixmap
diff -u khtmlw.org/htmltable.h khtmlw/htmltable.h
--- khtmlw.org/htmltable.h Thu Aug 19 12:49:10 1999
+++ khtmlw/htmltable.h Sun Aug 29 16:24:47 1999
@@ -79,7 +79,7 @@
{ HTMLClueV::print(_painter,_obj,_x,_y,_width,_height,_tx,_ty); }
void link() { refcount++; }
- void unlink() { if (--refcount == 0) delete this; }
+ void unlink() { if (--refcount <= 0) delete this; }
protected:
int rspan;
Only in khtmlw: htmltable.h~
Common subdirectories: khtmlw.org/test and khtmlw/test