Making objects persistent

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Making objects persistent

sergio_101
I am building a seaside application, and am in the process of building my models and unit tests.

I have a few objects that build up my data by creating objects. 

when i run the data creation methods, everything is fine. immediately afterward, since these objects to belong to anything, they are cleaned up by garbage collection.

is there a way to create these objects so that they persist? if this is possible, how would you go about deleting such a tenacious object?

thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

stepharo

Le 15/1/15 06:06, sergio_101 a écrit :

> I am building a seaside application, and am in the process of building
> my models and unit tests.
>
> I have a few objects that build up my data by creating objects.
>
> when i run the data creation methods, everything is fine. immediately
> afterward, since these objects to belong to anything, they are cleaned
> up by garbage collection.
>
> is there a way to create these objects so that they persist? if this
> is possible, how would you go about deleting such a tenacious object?

You should have an object pointing to them.

>
> thanks!


Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

philippeback
In reply to this post by sergio_101
On Thu, Jan 15, 2015 at 6:06 AM, sergio_101 <[hidden email]> wrote:
I am building a seaside application, and am in the process of building my models and unit tests.

I have a few objects that build up my data by creating objects. 

when i run the data creation methods, everything is fine. immediately afterward, since these objects to belong to anything, they are cleaned up by garbage collection.

 
is there a way to create these objects so that they persist?


They should belong to your session if you want them to live for the session.

Otherwise, I guess you can put them in a global var to make it available everywhere, or in 

GRObject>>applicationsession, or requestContext depending on how long you want them to live.

 
if this is possible, how would you go about deleting such a tenacious object?

Session expiry for session vars. The other ones, standard Smalltalk way, replacing the reference with something else innocuous if you can't get rid of them the normal gc way. 

Like, x become: String new. (and not x become: nil, which would make nil become x...)

thanks!








 

Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

jtuchel
Sergio,

I'D say you first need to define what you mean by "persistent" If all you need is to have them survive a Garbage Collection, you just need to make sure these objects are referenced by som eother objects. Depending on your use case, this can be Seaside Sessions, Global variables (probably the worst idea), TestCase subclasses or even a TestResource.

If you want to persist them for longer, we are talking about storage of objects, which is another beast. What comes to mind are options like Fuel, STON, Json, Voyage/Mongo or Glorp with some Database - the choices are endless.

Joachim


Am 15.01.15 um 08:32 schrieb [hidden email]:
On Thu, Jan 15, 2015 at 6:06 AM, sergio_101 <[hidden email]> wrote:
I am building a seaside application, and am in the process of building my models and unit tests.

I have a few objects that build up my data by creating objects. 

when i run the data creation methods, everything is fine. immediately afterward, since these objects to belong to anything, they are cleaned up by garbage collection.

 
is there a way to create these objects so that they persist?


They should belong to your session if you want them to live for the session.

Otherwise, I guess you can put them in a global var to make it available everywhere, or in 

GRObject>>applicationsession, or requestContext depending on how long you want them to live.

 
if this is possible, how would you go about deleting such a tenacious object?

Session expiry for session vars. The other ones, standard Smalltalk way, replacing the reference with something else innocuous if you can't get rid of them the normal gc way. 

Like, x become: String new. (and not x become: nil, which would make nil become x...)

thanks!








 



-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1

Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

Ben Coman
Store the objects in an array in a class variable.
To delete, just nil the class variable.

On Thu, Jan 15, 2015 at 3:44 PM, [hidden email] <[hidden email]> wrote:
Sergio,

I'D say you first need to define what you mean by "persistent" If all you need is to have them survive a Garbage Collection, you just need to make sure these objects are referenced by som eother objects. Depending on your use case, this can be Seaside Sessions, Global variables (probably the worst idea), TestCase subclasses or even a TestResource.

If you want to persist them for longer, we are talking about storage of objects, which is another beast. What comes to mind are options like Fuel, STON, Json, Voyage/Mongo or Glorp with some Database - the choices are endless.

Joachim


Am 15.01.15 um 08:32 schrieb [hidden email]:
On Thu, Jan 15, 2015 at 6:06 AM, sergio_101 <[hidden email]> wrote:
I am building a seaside application, and am in the process of building my models and unit tests.

I have a few objects that build up my data by creating objects. 

when i run the data creation methods, everything is fine. immediately afterward, since these objects to belong to anything, they are cleaned up by garbage collection.

 
is there a way to create these objects so that they persist?


They should belong to your session if you want them to live for the session.

Otherwise, I guess you can put them in a global var to make it available everywhere, or in 

GRObject>>applicationsession, or requestContext depending on how long you want them to live.

 
if this is possible, how would you go about deleting such a tenacious object?

Session expiry for session vars. The other ones, standard Smalltalk way, replacing the reference with something else innocuous if you can't get rid of them the normal gc way. 

Like, x become: String new. (and not x become: nil, which would make nil become x...)

thanks!








 



-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

sergio_101
Hi, all..

these are all ideas that make sense, and for the sake of any new people coming to pharo/smalltalk, i want to clarify just a little bit more what i am actually doing.

i am setting up a new site that needs to have a bunch of data available at all times. something like.. products, product types, pricing.. not really, but you get the idea. i have a class that just buzzes through and creates the data from some external CSV files.

this data will form the basis of the app.. very quickly this will be outdated.. but it will be a good place to start the app..

i plan on using gemstones as a data store when this goes live for real, but for now, i am just persisting data in the image, and will even do so on the proof site. when the site goes into production mode, i will set up gemstones.

since this is all happening completely out of seaside, i don't want to tie this to seaside at all. there are a few of these objects being created insides a test case, but they disappear pretty quickly after the tests are run.

i think what i am going to end up doing is creating a class variable that holds an array of these items. this should keep them available.

I will let you know. 

Thanks!



On Thu Jan 15 2015 at 4:52:30 AM Ben Coman <[hidden email]> wrote:
Store the objects in an array in a class variable.
To delete, just nil the class variable.

On Thu, Jan 15, 2015 at 3:44 PM, [hidden email] <[hidden email]> wrote:
Sergio,

I'D say you first need to define what you mean by "persistent" If all you need is to have them survive a Garbage Collection, you just need to make sure these objects are referenced by som eother objects. Depending on your use case, this can be Seaside Sessions, Global variables (probably the worst idea), TestCase subclasses or even a TestResource.

If you want to persist them for longer, we are talking about storage of objects, which is another beast. What comes to mind are options like Fuel, STON, Json, Voyage/Mongo or Glorp with some Database - the choices are endless.

Joachim


Am 15.01.15 um 08:32 schrieb [hidden email]:
On Thu, Jan 15, 2015 at 6:06 AM, sergio_101 <[hidden email]> wrote:
I am building a seaside application, and am in the process of building my models and unit tests.

I have a few objects that build up my data by creating objects. 

when i run the data creation methods, everything is fine. immediately afterward, since these objects to belong to anything, they are cleaned up by garbage collection.

 
is there a way to create these objects so that they persist?


They should belong to your session if you want them to live for the session.

Otherwise, I guess you can put them in a global var to make it available everywhere, or in 

GRObject>>applicationsession, or requestContext depending on how long you want them to live.

 
if this is possible, how would you go about deleting such a tenacious object?

Session expiry for session vars. The other ones, standard Smalltalk way, replacing the reference with something else innocuous if you can't get rid of them the normal gc way. 

Like, x become: String new. (and not x become: nil, which would make nil become x...)

thanks!








 



-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: Making objects persistent

Paul DeBruicker
In reply to this post by sergio_101
Here is another approach:

http://forum.world.st/Best-practices-available-for-Seaside-Gemstone-tp2721023p2901998.html

sergio_101 wrote
I am building a seaside application, and am in the process of building my
models and unit tests.

I have a few objects that build up my data by creating objects.

when i run the data creation methods, everything is fine. immediately
afterward, since these objects to belong to anything, they are cleaned up
by garbage collection.

is there a way to create these objects so that they persist? if this is
possible, how would you go about deleting such a tenacious object?

thanks!