Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 08-22-2014, 12:21 AM
Restraint Restraint is offline
NaS
Join Date: Jan 2014
Posts: 21
Restraint will become famous soon enough
Quote:
Originally Posted by Jakov_the_Jakovasaur View Post
hello!

tStaticVars should never be garbage collected for as long as they have an active reference, ive seen them remain for several months and only be destroyed whenever the npc-server is restarted

personally i prefer to store data within an sqlite database, however load the sql data into a tStaticVar cache upon database npc initialization for easier access
In theory, you are correct. It *should* never be garbage collected. However, it often is.

I ran into this problem thrice: once for a jailing/punishments system, once for a Graphics Viewer system, and once for some system I don't recall.

They all had active references, namely this.'s that were initialized onCreated. 2 of them were in DB NPCs, and 1 was in a Weapon NPC. They DO appear to have some arbitrary time limit.

If you never ran into it -- and I'm not doubting you -- I'm sure we can chalk this up as one of those "random Graal glitches."

I agree with you entirely with regards to SQLite Database and caching. I have also done similar with file databases and caching. Such caches make it very easy to submit data to the clientside as well (Again, via .saveVarsToArray()).
Reply With Quote
  #17  
Old 08-22-2014, 05:23 AM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 354
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
Quote:
Originally Posted by Restraint View Post
In theory, you are correct. It *should* never be garbage collected. However, it often is.

I ran into this problem thrice: once for a jailing/punishments system, once for a Graphics Viewer system, and once for some system I don't recall.

They all had active references, namely this.'s that were initialized onCreated. 2 of them were in DB NPCs, and 1 was in a Weapon NPC. They DO appear to have some arbitrary time limit.

If you never ran into it -- and I'm not doubting you -- I'm sure we can chalk this up as one of those "random Graal glitches."

I agree with you entirely with regards to SQLite Database and caching. I have also done similar with file databases and caching. Such caches make it very easy to submit data to the clientside as well (Again, via .saveVarsToArray()).
are you using the default onInitialized() event within database npcs as well?

i have always set up database systems in the following way:

PHP Code:
function onCreated()
  
this.onInitialized();

function 
onInitialized() {
  if (
this.cache == NULL) {
    
this.cache = new tStaticVar();
    
this.populateCache();
  } 

even prior to the introduction of tStaticVar() you needed to use onInitialize() within a database npc for it to be reliable
__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #18  
Old 08-22-2014, 11:03 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Someone explain what you guys mean by garbage collecting? And the initialization making it more reliable? How so?
Reply With Quote
  #19  
Old 08-22-2014, 04:31 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 354
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
Quote:
Originally Posted by scriptless View Post
Someone explain what you guys mean by garbage collecting? And the initialization making it more reliable? How so?
iirc the onCreated() event is not invoked when the npc-server is started, whereas onInitialized() is

garbage collection runs destroy objects that have no active reference, for example if you do this twice:

this.obj = new tStaticVar();

then the first object you created will no longer have an active reference, as that reference is now being used for the second object
__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #20  
Old 08-22-2014, 04:56 PM
Restraint Restraint is offline
NaS
Join Date: Jan 2014
Posts: 21
Restraint will become famous soon enough
It isn't an issue of not using onInitialized. I am talking about TStaticVars going AWOL hours after their creation without an NPC server shutdown or downtime in between.

In addition, yes, both of the DB NPCs I ran this in had onCreated() called in their onInitialized().

Like I said, I'm not doubting you that you've had success with TStaticVars not poofing. However, I've got several years of experience and troubleshooting this exact situation that say otherwise.

@Scriptless: Garbage collecting is a term used to mean that no-longer-references objects/variables are simply deleted after their references are gone.

The most common example of garbage collection is when a function terminates, its temp.variables are garbage collected unless stored elsewhere. That's what makes 'em temp.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.