xiaohongshu
xiaohongshu
77-webgl-jslib-memory-rules
Status: ACTIVE AppliesTo: v10 Type: Policy / Hard Rules
Full skill instructions
Status: ACTIVE AppliesTo: v10 Type: Policy / Hard Rules
WebGL .jslib ↔ C# 간 ptr/len/문자열 메모리 수명 규칙을 Hard Rule로 고정한다.
이 규칙을 위반하면 메모리 누수 또는 크래시가 발생한다.
.jslib가 _malloc한 모든 버퍼는 C#이 반드시 Free 호출로 반환해야 함| 이벤트 | 포인터 | Free 함수 |
|---|---|---|
| MESSAGE | dataPtr | WS_FreeBuffer(dataPtr) |
| ERROR/CLOSE | messagePtr | WS_FreeString(messagePtr) |
위반 시: WASM heap 메모리 누수 → 장기 실행 시 OOM 크래시
WS_PollEvent로 받은 ptr을 즉시 managed(ArrayPool)로 복사하고 ptr을 보존하지 않는다// CORRECT
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// ... 사용 ...
ArrayPool<byte>.Shared.Return(buffer);
WS_FreeBuffer(dataPtr);
// WRONG - ptr 보존 금지
_savedPtr = dataPtr; // 이후 Free 시점 불명확 → 누수/UAF
위반 시: Use-After-Free 또는 메모리 누수
const int MaxEventsPerTick = 64; // 권장값
for (int i = 0; i < MaxEventsPerTick; i++)
{
if (WS_PollEvent(...) == 0)
break;
// 처리
}
위반 시: 대량 수신 시 프레임 드롭, 메인 스레드 블로킹
ToArray() 금지, ArrayPool<byte> 사용 강제// CORRECT
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// ... 사용 후 ...
ArrayPool<byte>.Shared.Return(buffer);
// WRONG
byte[] buffer = new byte[dataLen]; // GC 압박
Marshal.Copy(dataPtr, buffer, 0, dataLen);
위반 시: GC 압박으로 프레임 스파이크, 핫 경로 allocation
case EventType.MESSAGE:
// 1. ArrayPool에서 버퍼 임대
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
try
{
// 2. Marshal.Copy로 복사
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// 3. core로 전달
_core.OnFrame(_sessionId, buffer.AsSpan(0, dataLen));
}
finally
{
// 4. ArrayPool 반환
ArrayPool<byte>.Shared.Return(buffer);
}
// 5. Free 호출 (반드시)
WS_FreeBuffer(dataPtr);
break;
case EventType.CLOSE:
string reason = "";
if (messagePtr != IntPtr.Zero)
{
reason = Marshal.PtrToStringUTF8(messagePtr);
WS_FreeString(messagePtr); // 반드시
}
EnqueueDispatch(() => OnClose?.Invoke((ushort)code, reason));
break;
아래 패턴이 문서/코드에 등장하면 FAIL:
Free 누락 가능성이 있는 설계
dataPtr를 필드에 저장하고 나중에 Free하는 구조ToArray() 또는 new byte[] 사용
이벤트 처리량 상한 없음
ptr 보존
WS_PollEvent에서 받은 ptr을 복사 없이 보관WS_FreeBuffer(dataPtr) 호출됨WS_FreeString(messagePtr) 호출됨ArrayPool<byte>.Shared.Rent()/.Return() 사용ToArray() 또는 new byte[] 미사용xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience