zhangyuang / node-ffi-rs

Implement ffi in Node.js by Rust and NAPI
MIT License
189 stars 7 forks source link

The process cannot stop automatically #38

Closed zgpio closed 5 months ago

zgpio commented 6 months ago

复现方法

  1. 创建如下文件 abc.ts
  2. ts-node .\winapi_reproduce.ts,运行之后程序没有自动终止
    
    // ts-node .\winapi_reproduce.ts
    import { funcConstructor, load, DataType, open } from "ffi-rs";

open({ library: "user32", // key path: "user32.dll", // path });

const HWND = DataType.U64; const LPARAM = DataType.I32; export async function enumChildWindows(hwnd: number) { const rv: Array = []; const func = (a: number, b: any) => { console.log(a=${a} b=${b}); rv.push(a); }; const rr = await load({ library: "user32", funcName: "EnumChildWindows", runInNewThread: true, retType: DataType.U64, paramsType: [ HWND, funcConstructor({ paramsType: [HWND, LPARAM], retType: DataType.Boolean, }), LPARAM, ], paramsValue: [hwnd, func, 0], }); return rv; } enumChildWindows(0);

zhangyuang commented 6 months ago

funcConstructor创建的函数不会被自动释放,readme中有提到。下个版本将会提供手动释放指针数据内存的函数

zhangyuang commented 5 months ago

参考最新的test.js中关于funconstructor的部分有提到如何释放内存