Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:52:21+00:00 2026-06-06T17:52:21+00:00

Currently I am developing a class which abstracts the SQLAlchemy. This class will act

  • 0

Currently I am developing a class which abstracts the SQLAlchemy. This class will act as helper tool to verify the values from database. This class will be used in regression/load test. Test cases will make hundred-thousands of database query. The layout of my class is as following.

class MyDBClass:
    def __init__(self, dbName)
         self.dbName = dbName
         self.dbEngines[dbName] = create_engine()
         self.dbMetaData[dbName] = MetaData()
         self.dbMetaData[dbName].reflect(bind=self.dbEngines[dbName])
         self.dbSession[dbName] = sessionmaker(bind=self.dbEngines[dbName])

    def QueryFunction(self,dbName, tablename, some arguments):
          session = self.dbSession[dbName]()
          query = session.query(requiredTable)
          result = query.filter().all()
          session.close()
    def updateFunction(self, dbName, talbeName, some arguments):
          session = self.dbSession[dbName]()
          session.query(requiredTable).filter().update()
          session.commit()
          session.close()
    def insertFunction(self, dbName, tableName, some arguments):
          connection = self.dbEngines[dbName].connect()
          requiredTable = self.dbMetaData[dbName].tables[tableName]
          connection.execute(requiredTable.insert(values=columnValuePair))
          connection.close()
    def cleanClose(self):
          # Code which will remove the connection/session/object from memory.
          # do some graceful work to clean close.

I want to write cleanClose() method which should remove the object which might be created by this class. This method should remove all those object from memory and provide a clean close. This may also avoid the memory leak.
I am not able to figure out what all object should be removed from the memory. Can some one suggest me what method calls I need to make here?

Edit1:

Is there any way by which I can measure the performance different method and their variant?
I was going through the documentation here and realized that I should not make session in every method rather I should create single instance of session and use throughout. Please provide your feedback on this. And let me know what would be the best way of doing thing here.

Any kind of help will be greatly appreciated here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:52:23+00:00Added an answer on June 6, 2026 at 5:52 pm

    To remove objects from memory in Python, you just need to stop referencing them. There is not usually any need to explicitly write or call any methods to destroy or clean up the objects. So, an instance of MyDBClass will be automatically cleaned up when it goes out of scope.

    If you are talking about closing down an SQLAlchemy session, then you just need to call the close() method on it.

    An SQLAlchemy session is designed for multiple transactions. You don’t generally need to create and destroy it multiple times. Create one session in the __init__ function and then use that in QueryFunction, updateFunction, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a custom control that derives from CStatic MFC class (Smart Device
I'm currently developing an app which uses the built-in Camera. I call this snippet
I'm developing on Android and currently haev various methods which manage my database in
I am currently developing an asp.net web app. I have a class which is
im currently developing an app which plays the steam audio using MediaPlayer class. And
I'm currently developing a database class for a project I've been working on. I
I'm currently developing an utility which is executing queries on a MySQL database and
Im am currently developing an automated test class (running several individual tests on other
Good evening, In my app that I'm currently developing, I have a class that
I am developing a web form using Visual Web Developer Currently I have class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.