From d10936a57eabee743df23857a9e90eae53dfe78d Mon Sep 17 00:00:00 2001 From: Qwreey Date: Thu, 5 Jan 2023 01:59:06 +0900 Subject: [PATCH] fix: Fixed gc issue --- exemple/elasticScrollFrame.lua | 8 ++++---- src/store.lua | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/exemple/elasticScrollFrame.lua b/exemple/elasticScrollFrame.lua index 0192556..fa09c5c 100644 --- a/exemple/elasticScrollFrame.lua +++ b/exemple/elasticScrollFrame.lua @@ -115,7 +115,7 @@ function scrollFrame:render(props) BackgroundColor3 = props "BackgroundColor3"; ZIndex = props "ZIndex"; ClipsDescendants = true; - [event.createdSync] = function (this) + [event.created] = function (this) this.InputChanged:Connect(function (input) if self._mouseDown or self._scrollbarDown then return; @@ -172,7 +172,7 @@ function scrollFrame:render(props) Size = props "CanvasSize"; ZIndex = props "ZIndex"; Position = UDim2.fromOffset(self._targetX,self._targetY); - [event.createdSync] = function (this) + [event.created] = function (this) self._holder = this; end; }; @@ -180,7 +180,7 @@ function scrollFrame:render(props) AnchorPoint = props "ScrollbarPositionY":with(function (_,value) return value == "Right" and Vector2.new(1,0) or Vector2.new(0,0); end); - [event.createdSync] = function (this) + [event.created] = function (this) self._scrollbarY = this; end; Position = props.ScrollbarPositionY == "Right" and UDim2.new(1,0,0,0) or UDim2.new(0,0,0,0); @@ -201,7 +201,7 @@ function scrollFrame:render(props) AnchorPoint = props "ScrollbarPositionX":with(function (_,value) return value == "Top" and Vector2.new(0,0) or Vector2.new(0,1); end); - [event.createdSync] = function (this) + [event.created] = function (this) self._scrollbarX = this; end; Position = props.ScrollbarPositionX == "Top" and UDim2.new(0,0,0,0) or UDim2.new(0,0,1,0); diff --git a/src/store.lua b/src/store.lua index 953a2ee..eb527a1 100644 --- a/src/store.lua +++ b/src/store.lua @@ -250,6 +250,7 @@ function module.init(shared) function new.__initStoreRegisterBinding(self,withItem) local selfTweens = self.__tweens; local selfValues = self.__self; + local selfKeep = self.__keep; for key,item in pairs(selfValues) do if type(item) == "table" and item.__type == "quad_register" then -- fetch data from origin @@ -270,11 +271,14 @@ function module.init(shared) end -- make event connection - item:register(function (_,newValue,eventKey) + local function regFn(_,newValue,eventKey) -- !HOLD IT SELF TO PREVENT THIS REGISTER BEGIN REMOVED FROM MEMORY local setValue = item:calcWithNewValue(withItem,newValue,eventKey); self[key] = setValue; - end); + end + item:register(regFn); + insert(selfKeep,item); + insert(selfKeep,regFn); end end end @@ -311,7 +315,8 @@ function module.init(shared) __self = self or {}, -- real value storage __evt = {}, -- changed event handler functions (dict of array) __reg = setmetatable({},week), -- save registers - __tweens = {} -- tweens (if inited with register, save tween and use as default tween data) + __tweens = {}, -- tweens (if inited with register, save tween and use as default tween data) + __keep = {} -- store data which should not be destoryed },store ); if id then -- save in id space