Panel servable app memory usage

I was digging a little more, and here’s what I learned.

I wrote my app as a Parameterized class, and all the big variables were allocated
as globals and used within the class methods when needed.

Now since these variables are allocated only once, the memory usage stays small even if I open multiple versions of the app. It keeps increasing, but by a very small amount.

This is how it looks (the relevant parts):

with open('datasets/entity_list_df.pkl', 'rb') as pkl:
    ENTITY_LIST_WORDCLOUD = pickle.load(pkl)

with open('datasets/papers_publish_time.pkl', 'rb') as pkl:
    PUBLISH_TIME = pickle.load(pkl)

START_TIME = PUBLISH_TIME.index[0].to_pydatetime()
END_TIME = PUBLISH_TIME.index[-1].to_pydatetime()

OMIT_WORDS_FROM_CLOUD = ['virus', 'viruses',
                         'Abstract', 'results',
                         'infection', 'infected',
                         'days', 'study', 'associated with',
                         'BACKGROUND', 'review', 'information',
                         'investigate', 'findings', 'studies']

class WordCloud(param.Parameterized):
    wordcloud_date_range = None

    def __init__(self):

        self.wordcloud_date_range = pnw.DateRangeSlider(
                                 name='Choose time period',
                                 start=START_TIME, end=END_TIME,
                                 value_throttled=(START_TIME, END_TIME),
                                 callback_throttle=1000)

        super().__init__()

on the other hand, if I override __init__ and allocate the variables as part of the class itself, the memory usage shoots up even when the bokeh server destroys the session.

This is how it looks (the relevant parts):


class WordCloud(param.Parameterized):
    wordcloud_date_range = None

    def __init__(self):

        with open('datasets/entity_list_df.pkl', 'rb') as pkl:
            self.entity_list_wordcloud = pickle.load(pkl)

        with open('datasets/papers_publish_time.pkl', 'rb') as pkl:
            self.publish_time = pickle.load(pkl)

        self.start_time = self.publish_time.index[0].to_pydatetime()
        self.end_time = self.publish_time.index[-1].to_pydatetime()

        self.omit_words_from_cloud = ['virus', 'viruses',
                         'Abstract', 'results',
                         'infection', 'infected',
                         'days', 'study', 'associated with',
                         'BACKGROUND', 'review', 'information',
                         'investigate', 'findings', 'studies']

So, it looks like variables allocated within a panel class do not get garbage collected once the session is destroyed. I have tried, and it does not matter if these variables are
class attributes or instance attributes.

Is this expected behaviour?