Re: ... clearing text in a GtkTextView!



This is an old thread, but it deals with something I'm wondering
about...

> * Roger Leigh (roger whinlatter uklinux net) wrote:
> > "Carl B. Constantine" <duckwing duckwing ca> writes:
> > 
> > > I have a GtkTextView in a window used for data entry into a database.
> > > The text typed in the view gets put in the database no problem, but once
> > > the data entry has occurred, I want to clear the view so that the next
> > > screen of data can be input.
> > 
> > Do you want to clear the *view* (the GtkTextView) or the *model* (the
> > GtkTextBuffer)?
> > 
> > If the former, you want to remove the TextBuffer and replace it with a
> > new one.
> > 
> > If the latter, you just need to clear the buffer.  Try something like:
> > 
> 
> > GtkTextIter start, end;
> > gtk_text_buffer_get_start_iter(textbuffer, &start);
> > gtk_text_buffer_get_end_iter(textbuffer, &end);
> > gtk_textbuffer_delete(textbuffer, &start, &end);

Does this clear out the data from memory, though?  I used this same
techique as shown above, but From the output of "memprof", I am doubting
it.  What I've come up with (and I think memprof shows an improvement)
is:   (freehand typing and generalization - may be typos)

  ------------------------ cut --------------------

GString *str; /* global */
gchar *strpt; /* auto */

if( <data in buffer> ) {
   <above routine to null out the buffer>
   g_string_free(str,TRUE);  /* New addition */
}

while reading data from file
  g_string_append(str, filebuffer);

strpt = str->str;
/* g_string_free(strpt,FALSE)*/  << commented out now, want to save for
                          next buffer load>>  
gtk_text_buffer_set_text (textbuffer, strpt, -1);
/* I think I could eliminate "strpt" altogether now, and in the previous
 * line, substitute str->str for strpt, right? */
----------------

Question is:  Am I correct here?  Is all this above code needed?  As I
said above, memprof _shows_ cleaner memory with the additional
g_string_free(str...), but is memprof accurate for all things like this?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]