Hi all!

I'm beginner in mozilla. I'm writing a C++ parser from HTML file to
its DOM implementation. I'm using mozilla nsIParser interface.

I have Sink class, inherited from nsIHTMLContentSink. There are
pointers to nsIParser and to Document objects there (Document is
structure, that not concerned with mozilla and contains parsed DOM
document). These pointers were defined outside of Sink class and
passed in by SetParser() and SetDocument() methods.

class Sink : public nsIHTMLContentSink
{
public:
    Sink() : domdoc(0), mParser(0) {}
    virtual ~Sink() {}

    void SetDocument(Document* tree)
    {
        domdoc = tree;
        // ...
    }

    NS_IMETHOD SetParser(nsIParser* aParser)
    {
        NS_IF_RELEASE(mParser);
        mParser = aParser;
        NS_IF_ADDREF(mParser);
        return NS_OK;
    }


    // ...

private:
    Document* domdoc;
    nsIParser* mParser;

    // ...

};

Before beginning parsing process, I'm creating an instance and setting
ContentSink for parser. Of course I do delete sink at the end of
parsing session.

Sink* sink = new Sink();

nsresult rv;
NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
if (NS_FAILED(rv)) {
    // ...
}

parser->SetContentSink(sink);

// ...

I gave about 1000 groups of about 10 documents to my parser and free
all resources after every group was parsed (I deleted all Document*,
Sink* and nsCOMPtr<nsIParser>, that free its resources automatically).
Program gobbled all my memory and swap space.

What's wrong with me?

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to