[ruby-talk:00290] Re: Ruby/Win32 question

From: matz@... (Yukihiro Matsumoto)
Date: 1999-04-27 02:41:38 UTC
List: ruby-talk #290
Hi.

In message "[ruby-talk:00289] Re: Ruby/Win32 question"
    on 99/04/26, "Bryce Dooley" <thecrow@cyberdude.com> writes:

|> Hmm, for example, IO objects are NOT destroyed on close(), even though
|> any operation on them are useless.  They raise exceptions for
|> operations after closing.  I think it's enough for treating
|> WM_DESTROYed Window objects as well.
|> 
|
|Matz, it sounds like this has potential to be a serious memory leak.
|Would that be a correct statement?

It should not cause memory leak.  Upon receiving WM_DESTROY event, you
should destroy internal window data structures, leaving wrapping Ruby
objects undestroyed.  I'm not certain for your implemantation, but
basic concept is like below:

  void
  wm_destroy_handler(struct RData *data)
  {
     struct window_wrap *win;

     Data_Get_Struct(data, struct window_wrap, win);
     WindowDestoryProcedure(win->id);
     DATA_PTR(data) = 0;    /* clear data field */
  }

You'd better check for destroyed windows at the top of all window
operation, e.g.

  static VALUE
  window_update(VALUE obj)
  {
     struct window_wrap *win;

     Data_Get_Struct(data, struct window_wrap, win);
     if (win == 0) rb_raise(rb_eWindowError, "destroyed window");
     WindowUpdateProcedure(win->id);
     ...
  }

Hope this helps.
                                                matz.

In This Thread

Prev Next