c-smile / sciter-sdk

Sciter is an embeddable HTML/CSS/scripting engine
http://sciter.com
Other
2.11k stars 224 forks source link

In SDK 4.4, C++ calls tscript method to have memory leak #192

Closed xiaoliang314 closed 3 years ago

xiaoliang314 commented 3 years ago

In Windows 10.

Example of using ulayered:

ulayered.cpp add code:

class frame: public sciter::window {
public:
  frame() : window( SW_MAIN | SW_ENABLE_DEBUG | SW_ALPHA | SW_GLASSY, wrc) { SetTimer(get_hwnd(), 200, 0, NULL); }

  char *build_random_hexs()
  {
      static char hex_chars[100];

      sprintf(hex_chars, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256,
          rand() % 256);

      return hex_chars;
  }

  virtual LRESULT on_message(HWINDOW hwnd, UINT msg, WPARAM wParam, LPARAM lParam, SBOOL& pHandled)
  {
      if (msg == WM_TIMER && wParam == 200)
      {
          for (int i = 0; i < 64; i++)
          {
              call_function("do_test", build_random_hexs());
          }
      }

      return window::on_message(hwnd, msg, wParam, lParam, pHandled);
  }

  BEGIN_FUNCTION_MAP
    FUNCTION_0("architecture", architecture);
  END_FUNCTION_MAP

  int architecture() {
    // this function is here just for the demo purposes,
    // it shows native function callable from script as view.architecture();
#if defined(TARGET_32)
    return 32;
#elif defined(TARGET_64)
    return 64;
#endif
  }
};

default.htm add empty function:

  function do_test(arg)
  {
  }

Run the program and you will see the memory keep increasing in the task manager.

c-smile commented 3 years ago

For the reference: https://sciter.com/forums/topic/in-sdk-4-4-c-calls-tscript-method-to-have-memory-leak/