ID:1885247
 
(See the best response by Nadrew.)
Code:
        menulist = new()

for(var/A in shopmenu)
var/obj/item/B = new A
if(level >= B.level)
menulist += B
if(!length(menulist))
return


Problem description:
I get that there are prolly other ways to do this. Im more worried about what happens to all the new items that the proc created when it creates new items to check if the player is a high enough level to use them. I know the shop keeper will only show items a player can use and thats how I want it but to avoid errors from null objects I have to create a new one of overything already in the shopmenu and then put them in the menulist if the player can use them.

Once the player buys the item he wants, he might shop again for another item, and do this like 50 times. See how it just keeps on creating new obj? Do these get deleted when the proc is over? Could these be sitting there in some kind of obj limbo, making it so every shop menu a player is shown takes up memory that is never freed? I hope I explained this good enough.
Best response
It really depends on how you're using the objects, by default any object with no references will be terminated by the garbage collector, which means objects created within a proc but not referenced by anything outside of the proc will be terminated.

If you want to avoid needlessly creating objects you can store the initial batch of creations in a global list (or a list contained by something with its own refernces) and use them over and over without creating or deleting them multiple times.
On a related note.
if(a.type == A.type)
and
if(istype(a, A))
would both be true if a and A are the exact same type but only the second would be true if a is type /obj/sword and A is just type /obj ?
I believe the second argument in istype() is always a type path, never an actual object, but otherwise yes.

That is, if A is /obj/sword, then istype(A,/obj) is true.