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 9064169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:10:54+00:00 2026-06-16T16:10:54+00:00

Well I guess this is not a normal how-to-do-this-or-that stackoverflow question, but perhaps someone

  • 0

Well I guess this is not a normal how-to-do-this-or-that stackoverflow question, but perhaps someone could enlighten me of a better approach for this question.

I’ve created an interface that could inherit different “engines” depending on a value and return the same object for all engines.
This is a short time flat rentals application that has some integration with other applications in other states, obviously each one has a API, so I have to know how to send and receive each one differently and inside my application to be able to have the same object for all APIs.
What I do exactly is I initialize something like this.

$flat = new API(array('engine' => 'some_api')); // the array has some more information inside but it is unimportant for the question

Now I have a list of IDs that each of them is for a different API.
Something like

$list = array(1 => 'api_1', 2 => 'api_2'); // and more ...

Now for the question!

When iterating over the $list what would you think is better,
Retaining all the possible engines inside the API object and for each ID I already have the “engine” initialized inside the API object (probably better speed/performance as everything is already allocated) or should foreach ID create a new API object with only the right “engine” initialized. (Lesser speed/performance but should be better on the memory management).

The API object has no meaning outside of the scope of the iteration so there is no need to retain it further down the line, but perhaps there would be less garbage collection overhead all in all if I just initiate one object instead of say 2 or 4 for the amount of IDs I have.

Any thoughts?

  • 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-16T16:10:55+00:00Added an answer on June 16, 2026 at 4:10 pm

    Creating/releasing objects doesn’t take that much memory or time. You shouldn’t have to worry about it, unless you have thousands of APIs.

    If there’s any external IO involved, like connecting to a server, initializing a database connection, querying meta information or reading a file, then it’s more efficient to do that as less as possible and only when you need to, but the number of objects in itself won’t impact the performance notably.

    Advice: Structure the code in the way that is most readable and maintainable for you. If you do, it is probably efficient enough. Only start restructuring if you really find a bottleneck.

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

Sidebar

Related Questions

this question probably wont be explained very well and that's because I don't really
Ok another WPF question, well I guess this is just general .NET. I have
This is not a question as such, but more like a list of things
I guess this is more or less a two-part question, but here's the basics
Well hi, guess what, I have an IE positioning issue! This is in 8,
Since this is my first question here on stackoverflow I hope my question is
I guess this problem is really about performance, but I'm trying to get a
Well I read that some new phones that will ice cream (4.0), will not
Okay, I guess this is entirely subjective and whatnot, but I was thinking about
I'm concerned that this might be working on an NP-Complete problem. I'm hoping someone

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.