At this time it is only deleted in the hashtable. If I do the extra delete then the program quits with the Kern-Exec 3 message.
I'm going to post a bit more code now:
HashTableElement.h:
Code:
#ifndef HASHTABLEELEMENT_H
#define HASHTABLEELEMENT_H
#include <e32base.h>
class CHashTableElement : public CBase {
public:
~CHashTableElement();
static CHashTableElement* NewL();
static CHashTableElement* NewLC();
void SetL(const TDesC8& _key, TAny *_object);
HBufC8* GetKey();
TAny* GetObject();
protected:
CHashTableElement();
void ConstructL();
private:
HBufC8* iKey;
TAny *iObject;
};
#endif /* HASHTABLEELEMENT_H */
HashTableElement.cpp:
Code:
/*
#include "HashTableElement.h"
_LIT8(KEmpty, "");
CHashTableElement* CHashTableElement::NewL() {
CHashTableElement *self = CHashTableElement::NewLC();
CleanupStack::Pop();
return self;
}
CHashTableElement* CHashTableElement::NewLC() {
CHashTableElement *self = new (ELeave) CHashTableElement();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CHashTableElement::ConstructL() {
iKey = KEmpty().Alloc();
}
CHashTableElement::CHashTableElement() {
}
CHashTableElement::~CHashTableElement() {
delete iKey;
iKey = NULL;
delete iObject;
iObject = NULL;
}
void CHashTableElement::SetL(const TDesC8& _key, TAny *_object) {
delete iKey;
iKey = NULL;
iKey = _key.Alloc();
delete iObject;
iObject = NULL;
iObject = _object;
}
HBufC8* CHashTableElement::GetKey() {
return iKey;
}
TAny* CHashTableElement::GetObject() {
return iObject;
}
HashTable.h:
Code:
#ifndef HASHTABLE_H
#define HASHTABLE_H
#include <e32std.h>
#include <e32base.h>
#include <e32cmn.h>
#include <EIKENV.H>
#include "HashTableElement.h"
class CHashTable : public CBase {
public:
~CHashTable();
static CHashTable* NewL();
static CHashTable* NewLC();
void PutL(const TDesC8& key, TAny* object);
TAny* Get(const TDesC8& key);
TBool Contains(const TDesC8& key);
void RemoveElements();
void Reset();
protected:
CHashTable();
void ConstructL();
private:
TFixedArray<CHashTableElement*, 1024> iTable;
RArray<TBool> iDeactivated;
TUint Hash(const TDesC8& string);
HBufC8* iCachedKey;
TAny* iCachedObject;
TUint iCachedHash;
CHashTableElement *iHashElement;
};
#endif /* HASHTABLE_H */
Hashtable PutL function:
Code:
void CHashTable::PutL(const TDesC8& key, TAny *object) {
TUint h;
if ((iCachedKey) && (*(key.Alloc()) == *iCachedKey)) {
h = iCachedHash;
}
else {
delete iCachedKey;
iCachedKey = NULL;
iCachedKey = key.Alloc();
h = Hash(key);
iCachedHash = h;
}
iCachedObject = object;
iHashElement = CHashTableElement::NewL();
iHashElement->SetL(key, object);
TInt tableIndex = h % 1024; // compression map
TBool inserted = EFalse;
if (iDeactivated[tableIndex]) {
delete iTable[tableIndex];
iTable[tableIndex] = NULL;
iTable[tableIndex] = iHashElement;
iDeactivated[tableIndex] = EFalse;
inserted = ETrue;
}
else { // Linear Probing
TInt i = tableIndex + 1;
while ((i < 1024) && (!inserted)) {
if (iDeactivated[i]) {
delete iTable[i];
iTable[i] = NULL;
iTable[i] = iHashElement;
iDeactivated[i] = EFalse;
inserted = ETrue;
}
else {
i++;
}
}
i = 0; // end of table reached
while ((i != tableIndex) && (!inserted)) {
if (iDeactivated[i]) {
delete iTable[i];
iTable[i] = NULL;
iTable[i] = iHashElement;
iDeactivated[i] = EFalse;
inserted = ETrue;
}
else {
i++;
}
}
if (!inserted) { // table is full
CEikonEnv::Static()->AlertWin(_L("Error: Hashtable is full"));
}
}
}
Hashtable Deconstructor:
Code:
CHashTable::~CHashTable() {
iDeactivated.Reset();
iDeactivated.Close();
delete iCachedKey;
iCachedKey = NULL;
iTable.DeleteAll(); ######CMessage should be deleted here!######
iTable.Reset();
}