Discussion:
Do I need to use RELEASEDOCUMENT when the editor control is destroyed?
Paul K
2013-09-03 19:49:41 UTC
Permalink
Neil, All:

I'm working on multi-view interface and can successfully create multiple
views for the same document (e1 and e2 are two wxStyledTextCtrl controls):

local docpointer = e1:GetDocPointer()
e1:AddRefDocument(docpointer)
e2:SetDocPointer(docpointer)

My question is: when one of the two controls is destroyed, do I need to try
to catch that event and call SCI_RELEASEDOCUMENT on docpointer? I read the
documentation on when ADD/RELEASE should be used (*
http://www.scintilla.org/ScintillaDoc.html#SCI_ADDREFDOCUMENT*<http://www.scintilla.org/ScintillaDoc.html#SCI_ADDREFDOCUMENT>),
but it's not clear if destroy the control does its own (internal) reference
count decrement and I don't want to decrement it too many times. Thank you.

Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Farshid Lashkari
2013-09-03 21:11:01 UTC
Permalink
Hi Paul,

The code in the Editor class destructor seems to indicate that the document
is automatically released upon destruction:

Editor::~Editor() {
pdoc->RemoveWatcher(this, 0);
pdoc->Release();
pdoc = 0;
DropGraphics(true);
}
Post by Paul K
I'm working on multi-view interface and can successfully create multiple
local docpointer = e1:GetDocPointer()
e1:AddRefDocument(docpointer)
e2:SetDocPointer(docpointer)
My question is: when one of the two controls is destroyed, do I need to
try to catch that event and call SCI_RELEASEDOCUMENT on docpointer? I read
the documentation on when ADD/RELEASE should be used (*
http://www.scintilla.org/ScintillaDoc.html#SCI_ADDREFDOCUMENT*<http://www.scintilla.org/ScintillaDoc.html#SCI_ADDREFDOCUMENT>),
but it's not clear if destroy the control does its own (internal) reference
count decrement and I don't want to decrement it too many times. Thank you.
Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Paul K
2013-09-03 21:35:51 UTC
Permalink
Post by Farshid Lashkari
The code in the Editor class destructor seems to indicate that the
document is automatically released upon destruction:

Thank you for the details; looks like no additional ReleaseDocument calls
are needed in my case.

Neil, it may be useful to mention this in the documentation as I got
confused by the strongly worded "you must balance each call to *
SCI_CREATEDOCUMENT* or *SCI_ADDREFDOCUMENT* with a call to *
SCI_RELEASEDOCUMENT*."

Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Neil Hodgson
2013-09-04 02:03:30 UTC
Permalink
Thank you for the details; looks like no additional ReleaseDocument calls are needed in my case.
You called SCI_ADDREFDOCUMENT so you must call SCI_RELEASEDOCUMENT. Not doing so will leave the document in memory. Set some breakpoints in a debugger to see if the document is ever freed.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Paul K
2013-09-04 03:56:09 UTC
Permalink
Post by Neil Hodgson
You called SCI_ADDREFDOCUMENT so you must call SCI_RELEASEDOCUMENT. Not
doing so will leave the document in memory.

I have two editors pointing to the same document. According to the
destructor code that Farshid shown, Release is called in the destructor,
which will decrement the reference counter. To make sure I understood
correctly, are you saying that I still need to call Release in that case
(two editors for the same document, one is being destroyed)?

Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Neil Hodgson
2013-09-04 04:11:14 UTC
Permalink
I have two editors pointing to the same document. According to the destructor code that Farshid shown, Release is called in the destructor, which will decrement the reference counter. To make sure I understood correctly, are you saying that I still need to call Release in that case (two editors for the same document, one is being destroyed)?
Well, what happens when you run this in a debugger?

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Paul K
2013-09-04 04:25:39 UTC
Permalink
Post by Neil Hodgson
Well, what happens when you run this in a debugger?
I don't. I use Lua interface that runs on top of wxwidgets, which includes
wxSTC component built around Scintilla, and am not even sure how to debug
this. I know how to debug the Lua layer, but not the lower level, hence the
question.

Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Farshid Lashkari
2013-09-04 18:09:48 UTC
Permalink
Hi Paul,

I don't believe you need to manually call AddRefDocument. According to the
docs, when you call SetDocPointer, it will automatically increase the
reference count by 1. I believe you only need to call AddRefDocument when
you want to store a pointer to a document that isn't assigned to any view.
So in your case I believe the following should suffice and the document
will be properly destroyed when both views are destroyed:

local docpointer = e1:GetDocPointer()
e2:SetDocPointer(docpointer)

This is how I share document views in my application and haven't noticed
any issues.

Cheers,
Farshid
Post by Paul K
Post by Neil Hodgson
Well, what happens when you run this in a debugger?
I don't. I use Lua interface that runs on top of wxwidgets, which includes
wxSTC component built around Scintilla, and am not even sure how to debug
this. I know how to debug the Lua layer, but not the lower level, hence the
question.
Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Paul K
2013-09-04 21:13:21 UTC
Permalink
Post by Paul K
local docpointer = e1:GetDocPointer()
e2:SetDocPointer(docpointer)
I'll try that. Thank you again, Farshid.

Paul.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...