3333    ckNotAllowed
3434    ckHand
3535
36-   Cursor *  =  ref  object 
36+   Cursor *  =  ref  CursorObj 
37+   CursorObj  =  object 
3738    when  defined (js) or  defined (emscripten) or  defined (wasm):
3839      c: jsstring
3940    elif  appKit:
@@ -76,7 +77,7 @@ elif appKit:
7677    of  ckNotAllowed: operationNotAllowedCursor ()
7778    of  ckHand: pointingHandCursor ()
7879
79-   proc  finalizeCursor (c: Cursor ) = 
80+   proc  finalizeCursorObj (c: CursorObj ) = 
8081    cast [NSCursor ](c.c).release ()
8182elif  not  defined (nimxAvoidSdl):
8283  proc  cursorKindToSdl (c: CursorKind ): SystemCursor  = 
@@ -94,7 +95,7 @@ elif not defined(nimxAvoidSdl):
9495    of  ckNotAllowed: SDL_SYSTEM_CURSOR_NO 
9596    of  ckHand: SDL_SYSTEM_CURSOR_HAND 
9697
97-   proc  finalizeCursor (c: Cursor ) = 
98+   proc  finalizeCursorObj (c: CursorObj ) = 
9899    freeCursor (c.c)
99100elif  defined (linux):
100101  proc  cursorKindToX (c: CursorKind ): cuint  = 
@@ -112,7 +113,7 @@ elif defined(linux):
112113    of  ckNotAllowed: XC_cross_reverse
113114    of  ckHand: XC_hand1
114115
115-   proc  finalizeCursor (c: Cursor ) = 
116+   proc  finalizeCursorObj (c: CursorObj ) = 
116117    discard 
117118elif  defined (windows):
118119  proc  cursorKindToWinapi (c: CursorKind ): LPTSTR  = 
@@ -130,15 +131,21 @@ elif defined(windows):
130131    of  ckNotAllowed: IDC_NO 
131132    of  ckHand: IDC_HAND 
132133
133-   proc  finalizeCursor (c: Cursor ) = 
134+   proc  finalizeCursorObj (c: CursorObj ) = 
134135    discard 
135136
137+ proc  finalizeCursor (c: Cursor ) =  finalizeCursorObj (c[])
138+ proc  `=destroy` (c: var  CursorObj ) =  finalizeCursorObj (c)
139+ 
136140proc  newCursor * (k: CursorKind ): Cursor  = 
137141  when  defined (js) or  defined (emscripten) or  defined (wasm):
138142    result .new ()
139143    result .c =  cursorKindToCSSName (k)
140144  else :
141-     result .new (finalizeCursor)
145+     when  defined (gcDestructors):
146+       result .new ()
147+     else :
148+       result .new (finalizeCursor)
142149    when  appKit:
143150      result .c =  NSCursorOfKind retain ()
144151    elif  not  defined (nimxAvoidSdl):
0 commit comments