Do i risk a memory leak or undefined behaviour if i do this?

Started by Nosky, October 28, 2023, 23:51:21

Previous topic - Next topic

Nosky

So basically i want to know what happens if i ever try to use the VkApplicationInfoHolder object after the stack is popped.

Does the memory not get freed because im referencing it (this.VkApplicationInfoHolder = TempVkApplicationInfoHolder;)?
Do i risk reading an area of memory that is not anymore allocated?
Do i risk having bad performance?


public class VkEngineApplicationInfo {

    private String instanceName, engineName;

    VkApplicationInfo VkApplicationInfoHolder;

    VkEngineApplicationInfo(String instanceName, String engineName){

        this.instanceName = instanceName;
        this.engineName = engineName;

        init();

    }

    void init(){

        try(MemoryStack TempStack = MemoryStack.stackPush()){

            //Application Info Struct
            VkApplicationInfo TempVkApplicationInfoHolder = VkApplicationInfo.calloc(TempStack);

            TempVkApplicationInfoHolder
            .sType(VK13.VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(TempStack.UTF8Safe("VkTest"))
            .applicationVersion(VK13.VK_MAKE_VERSION(1,0,0))
            .pEngineName(TempStack.UTF8Safe("yato"))
            .engineVersion(VK13.VK_MAKE_VERSION(1,0,0))
            .apiVersion(VK13.VK_API_VERSION_1_3);

            this.VkApplicationInfoHolder = TempVkApplicationInfoHolder;

        }

       
    }


}


Thanks in advance.