name = "Dark Mark"
icon = 'geoglyphs.dmi'
layer = MOB_LAYER -1
condor/icon_state = "condor"

set background=1

var/xl = 0
var/yl = 0

Z = new objtype(locate(cx+xl,cy+yl,cz))
Z.icon_state = "[ico_state] [xl],[yl]" = "[newname] Geoglyph"


yl = 0
xl += 1

M.ObjGrid += Z

if(xl<xsize) continue


//for(var/turf/T in view(30,usr)) if(T.z == z) T.overlays += /obj/geoglyph/shade

for(var/obj/geoglyph/G in usr.ObjGrid) del G

Problem description:

When i press Make Geoglyph its almost instant as it appears on the map. However when i press Del Geoglyph Dream Seeker seems to pause for quite a few seconds before it finally vanishs.

I added the objects to a list connected to the mob (ObjGrid), to avoid it having to sweep the world for those objects and hopefully saving some processing time/lag etc.

I'm not sure why it takes longer to delete the objects than it does to create them. Any thoughts? I'm a little concerned how the removal is going to affect the world on a live server.

Additionally, ive noticed what when i hit Close on the Dream Seeker window (while one of these is placed down on the map) then it takes its sweet time to close! About 3-5 seconds. Where as, closing it in all other circumstances its instant. Some issue with the code? I'm not really sure what though i think its about as good as it can be for the purpose of drawing a rather large 928x928 pixel image on a game map in real-time.
Read up on garbage collection and how explicitly deleting objects can be much more resource intense.
In response to Schnitzelnagler

Thankyou that is really helpful. So much to learn, seems like it could all never fit in my head :P not without pushing something else out lol.

That's very useful though, basically setting its loc to null will kill it. I just tried it and it was instant! So problem solved.

I never knew using Del() would be so resource intensive.
In response to EternalDuelistSoul
"Note that in the above list, loc does not count as a reference. If mob M is holding object O, O is referenced by M.contents but O doesn't necessarily have any references to M. The loc var doesn't need to add to the reference count, which is good because it means if you move the container to a null location and nothing else is using it anymore, all its contents can probably be deleted too."

Uh, huh.
In response to EternalDuelistSoul
Note that you'd also have to remove everything from the ObjGrid list, and the fastest way to do that is just to set it to list().
In response to Garthor
Garthor wrote:
Note that you'd also have to remove everything from the ObjGrid list, and the fastest way to do that is just to set it to list().

Good point, though the ObjGrid does store other objects so im just searching through types of what i want to remove.